This workshop is an introduction to the Strapi tool for an easy backend creation.
This workshop was made by:
Docker (see Startup part)
For this project, you'll need to clone this repository
git clone git@github.com:LucasClaisse/workshop-strapi.gitand you'll need docker and docker-compose installed on your computer
# Fedora 26
sudo dnf install docker docker-composeYou'll then need to start the docker service
sudo systemctl start docker.serviceYou can now launch the strapi application by running the following command from within the previously downloaded repository
docker-compose up --buildYou'll find the strapi documentation here.
First thing, do not use personal data on this exercices (personal password or emails) since the app in not secured to make it easier, the data send are not safe.
Before starting, you'll need an admin account, you can create one by going on the url http://localhost/ when the application is running
For exercice I and II, postman already created everything you need, it is just for you to understand how to communicate with your Application
You should already be abble to create an account, try to create one with Postman
Now that you have create an account, try to loggin to that account with Postman
Now that you have the bases, we will try to actually start using strapi. For that, get to the url: http://localhost/admin/ and create an admin account if not already done.
Now, you'll create a new Content Type, it's called a table in SQL.
Your table will be called Profile and will contains the following rows
- age: Number, it's an integer required field with a minimum value of 0 (see the advanced settings in strapi).
- date_of_birth: Date, it's a date not required field.
- major: boolean, it's a private and required field.
When your Content Type is done, do not forget to save your changes!
Once it's done, you should see a new Content Type on the left side of your admin page, create a new profile and put fake informations in it.
Now, you have create your first Content Type, but it is not actualy accessible with the api, you need to specify the permissions on this Content Type, take a look at the Roles and Permissions tab on the strapi admin page. Every user should be able to perform every requests on the Profile Content Type, change the permissions as requested and try to retrieve the number of profiles you have created with Postman.
To confirm that it's working, create a new profile and retry the same request.
You should now be able to retrieve a list of all profiles, try to find this list, it should look liike this
[
{
"id": 1,
"age": 14,
"date_of_birth": "2020-02-11",
"created_at": "2020-02-04T16:09:41.061Z",
"updated_at": "2020-02-04T16:09:41.061Z"
},
{
"id": 2,
"age": 21,
"date_of_birth": "2020-02-10",
"created_at": "2020-02-04T16:14:22.896Z",
"updated_at": "2020-02-04T16:14:22.896Z"
}
]Now that you know how Content Types work, you can now try to link a profile to a user, to link 2 tables, you use what is called a Relation.
So, you can go back to your Content Type Builder and add a field to the Profile Content Type. it should be as followed:
- 1 user can have 1 Profile and 1 Profile can have 1 user (yes, it's not the same)
- the field name is
userfrom theProfileContent Type - the field name is
profilefrom theUserContent Type
Don't forget to save
Now you should be able to link one of your previously created profile to the account you created in Exercice I
On this exercice, you'll have to try to retrieve a Profile from your user. The profile is now contain in the user, so only 1 request should be needed.