Exclude properties from useFetch
Hey there,
is it possible to exclude some properties when using useFetch? I've seen the
transform
-function and the pick
-function. With the former it would be possible, however the property is still transfered for the server but only ommited for the client.
Is there something similar like pick
to omit the property on the server request aswell?2 Replies
Hi @Theiaz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
No, there is currently no built-in option in Nuxt’s
-
- To avoid fetching unwanted data, you must adjust the API or use its filtering capabilities if available. See the official documentation for more details: Minimize payload size. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
useFetch
to exclude properties from the server response itself. Both the pick
and transform
options only affect the data that is included in the Nuxt payload sent from server to client—they do not prevent the unwanted properties from being fetched from the API in the first place. The full response is always fetched from the server, and only then are the selected fields included in the payload for hydration on the client.
To truly exclude properties at the source (i.e., to avoid fetching them from the server), you would need to modify the API endpoint itself to only return the desired fields, or use query parameters (if your API supports it) to limit the response.
In summary:-
pick
and transform
minimize the payload size sent to the client, but do not affect what is fetched from the server.
- There is no built-in omit
or similar option in useFetch
to exclude properties at the server request level.- To avoid fetching unwanted data, you must adjust the API or use its filtering capabilities if available. See the official documentation for more details: Minimize payload size. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@518773625537560576> Kapa.ai is still learning and improving, please let me know how I did by reacting below.