Feature request: Full support for Anonymous / Singleton resource
See original GitHub issueProposal: Support for Anonymous resources
So far there are only 3 kinds of operation allowed:
- item operations (these expects url contains an id)
- collection operations (these expects result is a collection)
- subresource operations
It is common need to define and document an endpoint, which have neither of these attributes, but could be (in given context - e.g. for given authenticated User) considered a singleton. e.g. ‘/me’ or ‘/user/current’ or ‘/auth/login’ or ’ /settings’ etc. It’s structure might be well defined, it is a single item (not a collection) it has no (or does need no) ID. Currently it is possible to implement this with custom item operation with a small hack, e.g. to specify:
/**
* @ApiResource(
* itemOperations={
* "get_current"={
* "method"="GET",
* "path"="/user/current",
* "controller"=GetCurrentUserController::class,
* "swagger_context"={
* "parameters" = {}
* },
* "openapi_context"={
* "parameters" = {}
* },
* "defaults"={"_api_receive"=false}
* }
* }
* )
*/
class User
{
}
but it might be bit of a hack.
It would be better, that ApiPlatform would allow defining ID-less / Anonymous / Singleton / Singular (pick your term 😃 ) resources standard way.
References:
(Official support not yet @teohhanhui in https://github.com/api-platform/api-platform/issues/199#issuecomment-270881649 on 6/1/2017)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (4 by maintainers)

Top Related StackOverflow Question
But we should probably rethink our arbitrary distinction of collection / item operations and the assumptions around that.
Btw. I would like to ask what is the ApiPlatform project relation to
https://medium.com/@ro0NL/domain-driven-design-projections-in-practice-with-api-platform-and-elasticsearch-c785ed6d660b ?
Seems that https://github.com/msgphp/symfony-demo-app might be using some interesting approach…