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

V2: add field filtering for properties of document ForeignKey #576

Open
calumbell opened this issue Oct 19, 2024 · 0 comments
Open

V2: add field filtering for properties of document ForeignKey #576

calumbell opened this issue Oct 19, 2024 · 0 comments

Comments

@calumbell
Copy link
Contributor

calumbell commented Oct 19, 2024

Description

Observed Behaviour. There is no way to control which fields are returned as children of the documents field returned by most items in the Open5e dataset.

Desired Behaviour. The ability to control which children of the document field are returned via query parameters. One specific use-case that would be especially useful on the frontend would be to have a way to only return document.name and document.key in the documents property and omit all other children.

Reproduction

  1. Visit the Open5e V2 API, I will use https://api.open5e.com/v2/creatures/srd_goblin/?depth=1 as an example but the bug can be observed in many endpoints
  2. Click on the Filter button and explore the filtering options for this endpoint
  3. Note that there is no way to filter the fields returned by the documents property

Context

It is currently possible to modify fields returned by an API query by including the appropriate query parameter in the endpoint URL. For example, hitting the https://api.open5e.com/v2/creatures/?fields=name,key only creautre names and keys are returned. This is a very helpful feature on the frontend to minimise the size of API responses to keep response times snappy.

However, with how API V2 is currently set up this is not possible on all fields. Specifically, you are not able to filter nested models stored as ForeignKeys. If you hit the https://api.open5e.com/v2/creatures/?fields=name,key,document endpoint, you will see that the document property returns all the data about the document, and that no option exists to request specific nested fields.

At a minimum, being able to request via query parameter that the document field should only return its name and key would allow large improvements to load times on the top-level pages of the frontend website.

Resources

Thanks to Tyler for flagging this article on the Open5e Discord. Within is described a programming-pattern which could provide the functionality requested

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

No branches or pull requests

1 participant