Skip to content
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

API query params presets #12104

Closed
etj opened this issue Mar 28, 2024 · 0 comments · Fixed by #12109
Closed

API query params presets #12104

etj opened this issue Mar 28, 2024 · 0 comments · Fixed by #12109
Assignees
Milestone

Comments

@etj
Copy link
Contributor

etj commented Mar 28, 2024

Short description

We want to define presets to be included in the API queries, that will be expanded server side in multiple query params.

Rationale

After implementing the fixes in #12079, it is now possible to request a specific set of fields, so that DB queries and data retrieval are optimized.

The GeoNode/MapStore client anyway performs some fixed requests, with a limited number of fields, but big enough t make the request URL cumbersome.

Proposed solution

In settings we can add the presets, for instance:

REST_API_PRESETS = {
"q1": {"exclude[]":"*", "include[]": ["pk", "title", "data"]},
"linked": {"exclude[]":"*", "include[]": ["pk", "linked_resources"]}
}

The requesting URL may be something like:
http://server/api/v2/resources?api_preset=q1

There will be a new Filter that modifies the request parameters, replacing the preset request with the related content; so the previous request will be the equivalent of:
http://server/api/v2/resources?exclude[]=*&include[]=pk&include[]=title&include[]=data

Pls note that the query params will be merged, so a request like
http://server/api/v2/resources?api_preset=q1&include[]=perms
will be transformed into
http://server/api/v2/resources?exclude[]=*&include[]=pk&include[]=title&include[]=data&include[]=perms

Caveats

The filter will only expand a preset wherever it is declared. It does not know whether the called entrypoint will really deal with the parameters, so it will be up to the client to make sure the preset will really work with the requested operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants