Strapi API Settings
In Strapi, there is no such thing as called format/ template for users to follow. When you create a Content Type, you will have a certain number of REST API endpoints available to interact with it.
So let’s strictly follow our tutorial below including collection/content types names, JSON serializer names, etc.
If you wish to customize your Strapi settings, refer to Strapi Docs for Strapi configurations and JSON-serializable plugin.
1. Define content types
1.1 Product content type
A Content Type, also called a model, is a type of data. The Strapi API includes by default, the user Content Type. Right now we need products, so our new Content Type is going to product (Content Types are always singular).
Here are the required steps:
- Navigate to the Content Type Builder in the sidebar (
http://your-site.com/admin/plugins/content-type-builderorhttp://localhost:xxxx/admin/plugins/content-type-builder). - Click on
+ Create new collection type. - Set
Productas name. - Click on
Continueand create the followings fields:
titlewith Short Text typevendorwith Short Text typeis_featuredwith Boolean typeis_out_of_stockwith Boolean typeis_activewith Boolean typeis_salewith Boolean typepricewith Number type, and decimal Number formatsale_pricewith Number type, and decimal Number formatreviewwith Number type, and integer Number formatinventorywith Number type, and integer Number formatimageswith Multiple Media typethumbnailwith Single Media typevideowith Single Media type, support to play Video type.
- Click on Finish
- Click on Save, the server should restart automatically.
Question: You might realize that some fields are not used in the project at all. Why should we implement it?
Answer: Those fields might not be used at the moment. However, they will be useful in the near future when we update new features. They would minimize errors as much as possible in those cases.
1.2 Product-category content type
Similar to creating a Product content type, repeat those steps, and create a Product-category content type with those fields:
titlewith Short Text typeslugwith Short Text typedescriptionwith Long text typefeature_imagewith Single Media type
1.3 Shipping content type
Create a Shipping content type with those fields:
titlewith Short Text typedescriptionwith Long Text typecostwith Number type, and decimal Number format
1.4 Payment content type
Create a Payment content type with those fields:
titlewith Short Text typedescriptionwith Long Text type
1.5 User content type
Create a User content type with those fields:
usernamewith Short Text typeemailwith Email typeproviderwith Short Text typepasswordwith Password typeresetPasswordTokenwith Short Text typeconfirmedwith Boolean typeblockedwith Boolean typedisplayNamewith Short Text type
1.6 Order content type
Create an Order content type with just 1 field: total with decimal Number format
2. Define relations
2.1 Product relation
- Go to Content-Types Builder at the left-hand side menu bar. Choose
Productcollection type then click+ Add another field - Create a many-to-many Relation with Product-Category content type as below:

- Also, create a many-to-many relation with
Orderas below:

2.2 Order relations
- In
Ordercontent type, create a relation withPaymentas below

- Create a relation with
Shippingas below

- Also, create a relation with
Useras below:

3. Create some entries
When completing all of your content types, the next thing that you need to do is to create some data for it (so that we can test later). To do so, click on Products under Collection Types list on the left-hand side menu bar. You are now in the Content Manager plugin: an auto-generated user interface that lets you see and edit entries. Let's create a sample product

And the final result would look like this:

Continue creating as many entries as you want that you would like to see on your app.
4. Allow access
When you are creating a content type, Strapi created a few set of files located in api/your-content-type-name. The find route is available at http://localhost:xxxx/your-content-type-name or http://your-site-url.com/your-content-type-name. However, due to Strapi APIS security, any access to those URLs would be blocked by 403 forbidden error. In order to let the app access your data, follow those steps:
- Navigate to the Settings then Roles & Permissions
- Click on the Public role
- Tick the
find,findoneandcountcheckboxes of the available routes - Save.
Important: do the same thing for the authenticated role.
Now go back to, for example, http://localhost:xxxx/products or http://your-site-url.com/products . At this point, you should be able to see your list of products.
That’s all 😊