Is there a built in way to filter the fields provided by the API response of a collection? I’m using Nuxt.js to statically generate a site and it needs a list of the slugs in an “slug”: “this-is-a-slug” type format. Can I filter the API results to ONLY show that field that are built into the API?
I saw the
fields option but it’s not really documented as to what it does.
If not, any tips on a solution?
Hello the fields field you can find it here the documentation.
Link: Mongolite User Manual
But this won’t return you an array of slugs anyway.
If you want to have custom bees you have to create in the “config” folder an “api” folder with your custom files inside that return the data as you want.
as always, it depends
if you want something re-usable then I would also recommend to do an addon, but if it is something project specific, then custom api entry points are a solution to solve things or provide specific data quickly
Let’s say, your collection
pages has two fields:
If you fetch your data
/api/collections/get/pages, you’ll receive
"title": "first entry",
If you want only the slug field, send the fields filter
and your response should look like this:
Is this possible to filter fields on get request ?
Sure. Just convert the filter into a query string: