Add possibility to pass arguments in {id} parameter in REST api

Created on 8 April 2025, 10 days ago

Problem/Motivation

I need to be able to add dynamic parameters in my query and for now only the id can be dynamic.
Example :
I have my api like this : https://example.com?id=1234
For now i can then configure my external entity to use "id" as id by configuring the "Single entity parameters" to
id={id}.
My api allow more parametters to be able to filter results, for example : https://example.com?id=1234&color=blue

In my complete example, i use a paragraph to load my external entity.
My paragraph has a field "id" and a field "color".
I want to be able to load my external entity a bit like :

$my_external_entity_blue = $this->entityTypeManager->getStorage('my_external_entity')->load("1234&color=blue");

Proposed resolution

Since the id data is passed, i propose to explode the current value into "id" to be able to add any other query needed.
That way, we can specify more parametters when we load an external entity.

Feature request
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium arwillame Belgium 🇧🇪

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @arwillame
  • Pipeline finished with Success
    10 days ago
    Total: 244s
    #468359
  • Pipeline finished with Success
    10 days ago
    Total: 235s
    #468372
  • 🇫🇷France guignonv Montpellier

    Hi!
    Thanks for the patch. For this feature, I had in mind to use features of the token module. But when I implemented that part, the token service was not part of the storage client services and it has recently been added.

    Wouldn't it be more powerful to just support token replacement as it would go beyond static values provided by the query as it could include dynamic values (such as current used login for instance, or a user token, etc.)?

    So I would prefer to keep using $this->entityTypeManager->getStorage('my_external_entity')->load("1234"); (to only keep a real id as parameter and keep the existing logic) and provide "color=blue" using another more generic mechanism in the single query parameters part (ie. ::getParametersFormDefaultValue('single')). I would see something either using tokens (which could return nothing if not available for instance) or using an event.

Production build 0.71.5 2024