Day 4 - Installing Strapi, Building Types, Relations
Housekeeping
- Assignment 1 due tonight
- Changes: added requirements for SiteMap
- Assignment 2 due Friday - announced tomorrow
1. Demo: Site Map
A quick build of a site map in Figma.
Creating labels/colours for:
- Single pages (i.e. About, Contact, etc)
- List entry pages (i.e. Gallery index page)
- Item Collection (i.e. one “page” that represents multiple items in a collection)
2. Demo: Strapi Installation and Content-type Builder
Materials
Instructions
Create a new project
$ npx create-strapi-app@latest my-project --quickstart
- Potential installation problems
- Port conflict: for example, Razor keyboards also use port 1337
- Solution
- Change Strapi port to 1338 (for exmaple) in
.env
file; - Rebuild your project
$ npm run build
- Run development server
$ npm run develop
- Change Strapi port to 1338 (for exmaple) in
- Solution
- Windows users:
- Node not installed
- Binary installer for Node
- Can also use Visual Studio Build Tools
- Select “Desktop Development with C++”
- Python not installed
- Install with Visual Studio Build Tools?
- Node not installed
- Port conflict: for example, Razor keyboards also use port 1337
- Potential installation problems
- Register the first administrator user
- Create collection types with the Content-type Builder
- Create new entries
- Set Roles & Permissions
- Publish the content
- Create API token
- Note: you only see the token once. Copy and Paste token somewhere safe, like a
.env
file in the root of your project:API_TOKEN=asdlfandsfj8373nehd93hdk...
- Using your token for requests:
- Open Postman;
- Enter your endpoint URL:
http://localhost:1337/api/articles
- You should get an “UnauthorizedError” because you didn’t supply a token;
- Go to Authorization in Postman to add your token:
- Type: Bearer Token;
- Token: Paste the token you copied from Strapi;
- Re-submit request and you should now receive the list of items.
- Note: you only see the token once. Copy and Paste token somewhere safe, like a
3. Demo: Enumeration vs Relation fields
Materials
- Slides: Strapi Content Types
- Enumeration fields
- Relation fields
Notes and gotchas
- If you edit a Relation after Entries have been added, you will need to re-set the Relation values in each Entry. Moral: add the minimum amount of content until you’ve finalized your Model to save you some time.
- The Strapi API won’t retrieve Relation data by default. You have to explicitly request the Relations with a
populate
query parameter:http://localhost:1338/api/resources?populate=*
4. Lab Time
Above and Beyond
- Categories and Subcategories with self-relation field
- Testing Deploy Guides: Find a host that has:
- Free tier
- No CC Required
Assignments