Best practice for returning partial responses?
![ribotmaximus](https://us.v-cdn.net/6037124/uploads/userpics/7N1U37LMJCZ3/nKDLUVDT5RH15.jpg)
Hi there everyone!
First time posting here and I'm still in the early stages of my learning journey with everything backend…
I really like human friendly RESTful API design and want to figure out how best to create an endpoint whose response changes depending on a querystring / or param value?
I've got a URI named /courses. I'd like the default response to return just a minimal list of course info e.g. ID and Name. Fine on it's own, but I'm struggling to figure out if an optional parameter was suppled e.g. /courses?expanded=true then I'd like to return a list of courses with all the course fields: ID, Name, Description, Created_at etc.
Alternatively, an approach similar to what Google offer works well: REST calls for partial responses take this format: e.g. GET https://library.googleapis.com/v1/shelves?$fields=shelves.name
which returns only a list of shelves.name values.
What are my options?
Looking forward to your responses and congrats on such a great platform!
Antony
Comments
-
Hi there hopefully this helps you with your query :)
-
Amazing, thank you for the Loom recording @Lachlan. Really appreciate you showing a few options. What I think I'm going to do now is the following:
- Use an add-on to expand the default response to cover a number of useful data points.
- Use an optional input parameter to provide a comma delimited list of fields to show
- Loop through the records and extract the relevant fields into an array
Many thanks for your help! I'll get back with any additional questions or learnings.
Antony
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback