Optimize your API requests with Strapi
Hello guys, today I’ll show you how to pass from this 🥴
to this 🥺🎉
TL;DR
Strapi allow you to remove attributes you don’t want the API response shows to the frontend. You might have various reasons but some of those could be: security or improve your API performances.
To do so, privateAttributes
is what you need.
- First open your code editor, then your 📁
api
folder to the endpoint you want to edit. - On the
options
property, you just have to addprivateAttributes
key. It's an array of string. - Fill it with attributes you want to keep private.
This also works with/for components.
Okay, Yodas! all you have to do now is save and refresh your browser 🙂
Hope you enjoy this article, if so like it and/or share it. Follow me on Twitter and let me know if you want me to cover another topic.
I’ve planned a playlist/serie on Strapi from Zer0 to Master, just wait for my mic to come.
Cheer!!! 🍻