Content Types in strapi are a collection of entered data represented by fields. Basically they are models in frameworks.
Create your first Content Types in strapi
First of all,
run your project using command
Once the project is started, navigate to http://localhost:1337/admin/. You will see something like this.
Time needed: 2 minutes.
Follow these steps on how to create a content types in strpai
- Click on content type builder from left admin panel
- Click on Add Content-Type
- Now you have to do some Content Type’s Settings
- Enter the name of your article let’s say it is news
- Give some description like latest news
- Now hit Done button
Now we have created our first content type but still, we are missing the fields that make up this content type so let’s go ahead and add these fields.
News article can have these three fields.
- title (type string)
- content (type text)
- image (type media)
Click on Add new field button and you will see a screen like this.
Let’s start by adding a title field, as the title should be String so click on the String button.
It will prompt a screen like this
Enter the name of the field (title) and navigate to the ADVANCED SETTINGS TAB. Here you can do some settings like you can set a default value, you can mark the field as a Required field, Unique Key, and you can also set the maximum and minimum length.
Now repeat the same process to add the remaining two fields and hit save button when done. Because of this action, strapi server will restart.
Once the three fields are added, let’s fill your content with data.
Fill your content with data
If you check Content Types on the left side of the admin panel you will notice a new content type with name News. Click on that and start adding some news in it. You will notice our three fields plus the Id. Follow these steps to fill your content with data.
- Click on Add New News Button to create news through admin panel
- Add title, Content, and image
- Hit save button
Ok great! Congratulations you have added your first news.
Fetch Data through API
Ok, let’s test our API, head over to browser and type http://localhost:1337/news (news is our content type). You will see a Forbidden error with a 403 status code.
We need to add some permissions to our content type news. Now click on roll and permissions from admin panel then click on Public, scroll down a bit and in Permissions section looks for News that is our content type. Click on find and on the right side you will notice a /news route.
Hit the save button.
Let’s test out this API again in the browser, and type the same URL. it’s working perfectly fine. Now we have successfully given permission to this route.
To enhance your knowledge regarding advanced technologies, tune to Morosoft tweaks https://www.mstweaks.com/. If you want to be up to date with all that is happening in the world, Morosoft Tweaks is providing you all under one roof. We also aim to provide relevant information in a quick and sophisticated manner. Contact us: firstname.lastname@example.org