RESTful/Laravel API
Corben78 opened this issue · 2 comments
Is it possible to configure the API that's being queried to be like a RESTful (Laravel) API?
I see that when I request an item of a resource, that's done by adding GET parameters, e.g. https://example.com/users?id=1
But my API (provided via Laravel) is using URLs like this: https://example.com/users/1
By default if you have an endpoint such as GET /users
:
- which allows to fetch multiple users at once
- allows to pass extra query parameters to filter/order the results: let's say
?name=john
to retreive all John users
You will do something like this:
User::where('name', 'john')->get(); // Internally calls /users?name=john, It will return a Collection
Then if you have an endpoint GET /users/{id}
- which allows to fetch one user by its id
You will do such as below:
// User with id 1 exists in the API
// Internally calls /users/1, It will return a User model filled with data received from endpoint
User::find(1);
// User with id 2 does not exist in the API
// Returns null
User::find(2);
So if I well understood your question, it is already the default behavior for php-api-wrapper, but let me know if I didn't get your question.
Thanks for your answer.
Sorry to answer this late, haven't had the chance to look into this more yet. Atm I'm using a different approach, but might come back to this later.