-
Notifications
You must be signed in to change notification settings - Fork 107
Singular Resources #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @lindyhopchris So after this we can add any route we want and place custom actions in same controller. With this solution I added /users/me route and map it to method in UsersController class. This class extend EloquentController and serve all json-api stuff. Is it good solutions? Or not? What side effects can we get with such solution? Thanks in advance |
or maybe @jstoone have thoughts about this |
If that works at the moment then I suppose it might be acceptable at the moment. I think the more permanent solution going forward would be to use the options when registering the JSON-API resource with the route That should be fairly straight-forward to do, but we'd then need to follow through what happens with all the parsing of the request to check that it doesn't start throwing exceptions elsewhere. The main problem is that because the endpoint is not defined in the spec, it's not really possible to know how to validate the request content for a |
This sounds like a really neat feature! The first thought that hit me, was that these singular resources sound very much like an alias to me. And since the singular resources are ideally going to be quite few, I'd actually suggest an implementation that could fit in either the // The array key is the JSON:API `resourceType`
// The array value is the ID identifier for the resource
// The last string argument is the final alias to get the resource
JsonApi::resourceAlias(
['users' => auth()->id()]
'/users/me'
); NB: for simplicity sake lets assume the currently authenticated user has an ID of 5
I might not have understood or not think the solution through, so I hope it makes sense @dmitry-php @lindyhopchris. 😄 |
@lindyhopchris I think I'll start taking a look at this, and then we can iterate if it does not seem to fit the style you have in mind. 🙂 All of a sudden laravel-json-api got a lot of activity. Nice! Let the work begin! 😅 |
@jstoone sorry, meant to reply earlier. The alias won't work because you won't have the authenticated user id at the time that you are registering routes. |
@lindyhopchris hmm maybe we could enable the resource value to be a closure? In that way we could evaluate the value when transforming the aliased request? |
Closures won't be compatible with I think it's some sort of config in the options that can be passed to Also I'm planning to make some changes to the routing stuff so that the current |
Closing this as it is effectively solved via #196 I.e. in JsonApi::register('default')->withNamespace('Api')->routes(function ($api) {
$api->resource('users')->controller()->routes(function ($posts) {
$posts->get('me', 'current');
});
}); Which would mean |
Add support for registering routes of singular resources:
http://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/5
The text was updated successfully, but these errors were encountered: