CristalTeam / php-api-wrapper

:rainbow: Work with APIs like with Laravel Eloquent or Doctrine (no longer a dream)
MIT License
117 stars 32 forks source link

RESTful/Laravel API #26

Closed Corben78 closed 2 years ago

Corben78 commented 3 years ago

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

TZK- commented 3 years ago

By default if you have an endpoint such as GET /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}

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.

Corben78 commented 2 years ago

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.