INTRODUCING STRAPI — A Headless CMS and API development

Olufemi Oluoje Kazeem
4 min readAug 6, 2018

Strapi is the most advanced Node.js API Content Management Framework. Halfway between a Node.js Framework and a Headless CMS, it saves weeks of API development time.

The most basic feature of a Strapi API is to expose a CRUD. That means you can easily get, create, update and delete entries.

In this article you will learn how to build powerful, secure and fast API in Node.js without writing a single line of code.

So, let dive in!

Strapi Setup

To setup Strapi, you must have the following installed

  1. Nodejs (version 8 or higher)
  2. MongoDB (2.6)

We will be installing Strapi with npm globally on command line:

$ npm i strapi@alpha -g

The above command will install Strapi globally using the Node package manager.

Strapi has been installed globally, we now have access to the `strapi` command.

If you have permissions error, you can follow the official npm tutorial or run it with root permission that will ask for the root password. See the command below:

sudo npm install strapi@alpha -g

To check if Strapi installed, copy and paste the command below to your command line:

strapi -v

This should output something like3.0.0-alpha.x.x.x.

If your output is similar to the one above, you have successfully installed Strapi.

Create a Strapi Project

On your command line, follow the instructions below.

strapi new api

This will create api folder and bootstrap a new Strapi project into api folder created.

Change directory to the folder created which is api:

cd api

Then, start the server:

strapi start

The above command will launch Strapi project and you can see it by typing `http://localhost:1337 on the address bar your browser.

If you visit `http://localhost:1337/admin` you will be ready to create the first user that will manage Strapi which is the ADMIN.

Creating First User

Creating first user

Creating API

To create API you will need a Strapi plugin called Content Type

Create A Content Type

To create a an API at the backend using Strapi CMS, we need a content type plugin to create the contents and generate its APIs endpoints.

Under Plugins Menu, click on Content Type.

Create a Content Type named Post with three fields:

  1. title (type string)
  2. slug (type string)
  3. content (type text)
  4. cover (type media)
  5. author (type relation, many posts to one user)

Then, click on Save button.

Creating Post

We will be inserting contents into the database using the Post content type we created above:

  • Visit Post page(which is at the top left corner of your screen)
  • Click on add new Post
  • Enter values to the Title, Author, Cover, Slug and Content fields
  • Click on save

Create two more posts.

Access Control

For security reasons, API access is, by default, restricted. To allow access, visit the Auth and Permissions section for Guest role, select the Post, find action to allow access for guest, then click on save button.

At this point, you should be able to request the list of posts using the GET method.

The author API access is also restricted. Authorize anonymous access by selecting the find (in “Users & Permissions” section) action and save the form.

If you visit http://localhost:1337/posts on the browser or using the GET method on POSTMAN, you will see the list of posts you created.

You can see how easy to create powerful and secure APIs without writing any code using Strapi.

The documentation page is a good place to start to learn Strapi.

You can also join Strapi community here http://slack.strapi.io . You will be able to ask questions related to Strapi and there are mentors to guide you and they will help you in journey of learning how to use Strapi for your frontend projects.

Conclusion

If you are a Frontend developer, you are going to love Strapi as it helps you to saves time on developing APIs. You can use Strapi with Reactjs, Vue, Angular, Javascript etc. As you know that all frontend frameworks relies on APIs to communicate with backend.

In the next article, we will be looking at React.js with Strapi.

--

--

Olufemi Oluoje Kazeem

Olufemi Oluoje Kazeem is a software developer with over 7 years of experience. He is a mentor and coach.