Optimize your API requests with Strapi

·

1 min read

Hello guys, today I’ll show you how to pass from this 🥴

Screen Shot 2021-05-20 at 03.27.25.png


to this 🥺🎉

Screen Shot 2021-05-20 at 03.22.33.png

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 add privateAttributes key. It's an array of string.
  • Fill it with attributes you want to keep private.

This also works with/for components.

Screen Shot 2021-05-20 at 03.36.34.png

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!!! 🍻