jeudi 15 octobre 2015

The concept of GET request on API - Laravel 5

I'm trying to develop a REST API on Laravel 5.1. After reading 10 Best Practices for Better RESTful API by Stefan Jauker and Best Practices for Designing a Pragmatic RESTful API by Vinay Sahni, I couldn't conclude the proper handling of the index() method in cases of filtered data.

Route::group(['prefix' => 'api'], function() {
    Route::post('login', 'AuthenticateController@login');

    Route::group(['middlware' => ['jwt.auth']], function() {    //, 'jwt.refresh'
        Route::resource('customer.ticket', 'Customer\TicketController');
    });
});

Now the question is, assuming I can only see the tickets I opened, is it ok for me to filter the data being returned by index method?

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index($customerId) {        
    return response($this->ticket->where('creator_id', $customerId)->get());
}

Because when reading about REST API, you get the point that a GET in /endpoint should return "ALL" data. I'd like to validate that all data does not necessarily means SELECT * FROM table, but instead means get all resource data for what I'm requesting.

Is there another conventional way to tackle this that I'm not aware?

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire