question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Full support for Anonymous / Singleton resource

See original GitHub issue

Proposal: 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
teohhanhuicommented, Jul 19, 2019

But we should probably rethink our arbitrary distinction of collection / item operations and the assumptions around that.

0reactions
slavo2commented, Jul 19, 2019

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP features in Durable Functions - Azure - Microsoft Learn
Orchestrations and entities can be invoked and managed using HTTP requests. The Durable Functions extension exposes built-in HTTP APIs.
Read more >
Singleton routes for one-off resources in Laravel 9.x
Laravel 9.x introduced a new feature called singleton routes which allows you to define a route for a one-off resource like settings in...
Read more >
Simplest/cleanest way to implement a singleton in JavaScript
I think the easiest way is to declare a simple object literal: var myInstance = { method1: function () { // ... },...
Read more >
Classic Cluster Singleton - Documentation - Akka
Akka Classic is still fully supported and existing applications can continue to use the classic APIs. It is also possible to use the...
Read more >
Inline Singleton | Refactoring to Patterns: Creation - InformIT
I've rid myself of Singletonitis and am now considering starting “Singletons Anonymous,” a place where recovering Singleton abusers can support ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found