Original post from series "Building an App with Gatsby and Strapi"
Who is this post for? Each post in the series is loosely dependent on each other. So you can follow any post in any order you like. Posts were made this way so you donโt have to read all the previous ones to follow along.
The goal of this post is to explore Strapiโs REST API in regards to:
- setting up the API,
- setting up API permissions,
- documenting and testing API endpoints.
Setting Up
Okay, so far the post is a bit misleadingโฆ Strapi automatically generates content API endpoints for CRUD (create, read, update, delete) operations when you create or modify content types ๐ So we donโt have to worry about this step!
Setting Up API Permissions
Before we can use the generated API, we will need to define who has permission and to what actions. For example, lets look at the Page content type and give the Public role permission to call count
, find
, and findone
actions (actions are simply the functions used by the controller to perform business logic).
Step 1 โ Ensure the content type is defined as needed
Step 2 โ Go to Roles & Permissions and select the Public role
Step 3 โ Give permission to use the actions
Documenting and Testing the API
There are multiple ways to test this, but for this post I recommend is using Swagger UI. Itโs a nifty tool that automatically generates documentations for REST APIs. To set up, run the following command in your terminal in the root folder of the strapi instance.
npm run strapi install documentation
Restart Strapi. A new UI section is then created to manage the documentation. Here you can access the documentation, test responses, and restrict access to the documentation.
Top comments (0)