System Information
-
Strapi Version: 4.4.3
-
Operating System:
-
Database: Postgress
-
Node Version: 16.17.0
-
NPM Version: 8.19.2
-
Yarn Version:
Is there any possibility to reduce media response just to url, name and altText?
This response is so huge and I dont need all of this attributes in response. I have kind of big response with a lot of media and this icon object makes it like 3 times more expensive.
EDIT
I also want to add that icon is a part of strapi component
You can use the populate
parameter.
Ignoring that icon is placed within a component, you can just do
GET:/api/content-type?populate[icon][fields][]=url&populate[icon][fields][]=name&populate[icon][fields][]=altText
to fetch just the desired fields.
Adjusting for the component you’d just nest the params one more level.
What about nested objects like “formats”? What if I want to select “formats” like this:
populate[icon][fields]=formats
but only url key from it.
Neither that:
populate[icon][fields]=formats.thumbnail.url
or that
populate[icon][fields][formats][fields][thumbnail][fields]=url
work. Both throw 500
@Dawid_Jazdzewski
What about nested objects like “formats”?
Well, that depends. A field can take form of a nested object in the API response for multiple reasons:
- it’s a relation
- it’s a component (which is in fact just a special case of relation)
- it’s a media field (again a special case of relation)
- it’s a Dynamic zone
- it’s a JSON field
The populate
and fields
parameters, to my knowledge, are supported only for the basic relation fields i.e. relations, components and media.
The format
field of the plugin::upload.file
content-type is a JSON
field and hence cannot be fetched partially.
You could work around this by implementing a custom controller that strips out everything you don’t need from the response.