How to Build a Movie Database & API with Strapi

API API
Headless CMS Headless CMS
Strapi Strapi
Web Development Web Development

Strapi is an awesome headless CMS built with Node.js that can speed up the process of building an API quiet dramatically. It's perfect for people who enjoy the frontend more than the backend, and it allows you to build complex database structures with out writing any code. Magic, if u ask me.

To visualize the potential of Strapi I thought that we would create a Movie Database & API. I chose this concept instead of a classic "Blog" tutorial as I thought it would better showcase the Strapi's capabilities.

A movie database needs a few things to be useful. We need Movies and Genres, but to make things a little more interesting we could add Actors and Directors.

To follow along in this tutorial there are a few requirement that you should know of. Strapi requires a package manager (NPM or Yarn) and Node.js to operate.

  • Node.js >= 10.x
  • NPM >= 6.x

Install Strapi

Open up your terminal on your computer and navigate to the directory where you want to install your project.

cd directoryname

Strapi can be installed via two package managers, NPM and Yarn. I personally enjoy NPM but the choice is up to you.

#NPM

npx create-strapi-app moviedb --quickstart

#Yarn
yarn create strapi-app moviedb --quickstart

Once your installation is complete you can navigate to http://localhost:1337/admin and create an admin user account. 

How to Build a Movie Database & API with Strapi

As soon as you have created your admin account you get greeted by the Strapi's beautiful admin panel.

Since we flagged our project with the --quickstart flag during the installation our project comes preconfigured with SQLite as our database, as well as a few plugins installed by default. 

The Content Type Builder, File Uploads and Roles & Permissions are some of those plugins that was installed and we will make use of all of them during this tutorial.

But first we will take a look at the Content Type Builder as it is the bread and butter of Strapi.

With the Content Type Builder you can create database models and specify fields and relations. Strapi will then automatically generate API endpoints for each Content Type (without you writing any code). It's pretty cool, if you ask me.

Create Content Types & Fields

As we are building a Movie Database we will need a few different content types to make things a little more interesting.

  • Movies
  • Genres
  • Actors
  • Directors

Navigate to the Content Type Builder and click Create new content-type.

A movie will need some specific fields to display valuable information for our API, let's start with the basic once.

Movies

  • Title (text field) - the name of the movie.
  • Thumbnail (media field) - will handle uploads of a movie poster.
  • Description (rich text field) will house information about the movie.

Add the fields specified above to your Movies Content Type.

How to Build a Movie Database & API with Strapi

When you are done adding the fields click the green save button in the top-right corner. This will take some time as Strapi is creating the database models and corresponding fields.

How to Build a Movie Database & API with Strapi

Your Movies Content Type should now contain the following fields.

How to Build a Movie Database & API with Strapi

As you can see we now have a new Content Type called movie in our left sidebar, awesome.

We repeat this process for all the other necessary Content Types.

Genres

  • Title (text field) - will be the name of the genre.
  • Description - a description of the genre.
How to Build a Movie Database & API with Strapi

Actors

  • Name (text field) - Name of the actor.
  • Thumbnail (media field) - will handle uploads of an image of the actor.
  • Description - a description of the genre.
How to Build a Movie Database & API with Strapi

Directors

  • Name (text field) - Name of the director.
  • Thumbnail (media field) - will handle uploads of an image of the director.
  • Description - a description of the genre.
How to Build a Movie Database & API with Strapi

API Endpoints & Permissions

Good Stuff, the foundation of our API is done, let's have a look at our newly created API Endpoints.

http://localhost:1337/movies

Most certainly you will receive a 403 forbidden when you visit the url.

{"statusCode":403, "error":"Forbidden", "message":"Forbidden"}

Don't worry though, it's actually a good sign, it means that your endpoints are protected.

To fix this you need to make the endpoint available for public consumption.

We can do that in Strapi's admin panel under Roles & Permissions.

Click the Public profile and add permissions for "find" and "findone" on each of the content types.

How to Build a Movie Database & API with Strapi

"find" represents permission for the list:

http://localhost:1337/movies

"findone" represents permissions for each individual item:

http://localhost:1337/movies/12

Navigate back to your API Endpoint now.

As you can see, we no longer receive the error 403 forbidden, instead we get an empty array. Awesome!

[]

Your API is now available for public consumption. But don't just take my word for it, add a movie yourself and you can see that the movies are added to the API.

{
    "id": 1,
    "Title": "Fury",
    "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
    "created_at": "2020-02-07T10:56:55.724Z",
    "updated_at": "2020-02-07T10:56:55.724Z",
    "Thumbnail": [
        {
            "id": 1,
            "name": "fury.jpg",
            "hash": "fd3d650cede946dd866aa1bb752323ab",
            "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
            "ext": ".jpg",
            "mime": "image/jpeg",
            "size": 88.22,
            "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
            "provider": "local",
            "provider_metadata": null,
            "created_at": "2020-02-07T10:56:55.799Z",
            "updated_at": "2020-02-07T10:56:55.799Z"
        }
    ],
}

Strapi & Relationships

The power of relational databases lies in the ability to form relationships between entries, hence the name relational database. Rather than writing everything over and over again relationships can help us make things less redundant.

For example, rather than writing each actor and director into a field into the move content type (database table) we create a table that will house actor and one for directors, and then link them to each movie. This way we don't have to repeat our self for each and every movie, rather just select actors and directors from a dropdown list.

The power of relationships does not stop there. What if you want to show all movies directed by a specific director? Well the relationships got you covered here as well. Imagine if you had to write each director page by hand, and how hard it would be to keep up with each new movie release for every director, or actor for that matter.

There are a few types of relationships that has their own use-cases and their own unique power. Foreign Keys, OneToOne, OneToMany, ManyToOne and ManyToMany Relationships.

In Strapi they are named accordingly:

  • has one relationship
  • has and belongs to one relationship
  • belongs to many relationship
  • has many relationship (forward)
  • has and belongs to many relationship
  • has many relationship (backwards)

You can use these types of relationships by adding a relationship field to your Content Types.

Specifying what type of relationship it is and point it between the selected content types.

When you save your field, Strapi will automatically create pivot tables and handle everything for you in the background. That is drastic improvement for people who don't enjoy spending time writing backend code, schema and handle migrations.

To seasoned developer there might still be some limitation to this magic, but for the average frontend developer and content creator it's a complete game-changer.

Lets create the necessary relationships for our Movie Database.

The Movies content type needs  "has and belongs to many" relationships with the with the Actors, Directors and Genres Content Type.

Add a "has and belongs to many" relationship field from Movies to Actors

How to Build a Movie Database & API with Strapi

Add a "has and belongs to many" relationship field from Movies to Directors

How to Build a Movie Database & API with Strapi

Add a "has and belongs to many" relationship field from Movies to Genres

How to Build a Movie Database & API with Strapi

Add Mock Data to Your Movie Database & API

Usually when adding mock data I would use some sort of Faker library that automatically populates data into both fields and its relations. However, since its the first time ever using Strapi I am not aware of such library, so I added it manually.

I guess its good since it will make this tutorial more readable to people used to creating APIs in the first place.

I will not go into detail on how I add the data though. If you have added data into any type of forms on the web before, you should be good to go.

So go ahead and add Genres, Actors, Directors, and finally Movies to your liking.

How to Build a Movie Database & API with Strapi

As you can see, we can now add movies and simply selecting the Actors, Directors and Genre that is already in our database.

How to Build a Movie Database & API with Strapi

http://localhost:1337/movies/

[
    {
        "id": 1,
        "Title": "Fury",
        "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
        "created_at": "2020-02-07T10:56:55.724Z",
        "updated_at": "2020-02-07T10:56:55.724Z",
        "Thumbnail": [
            {
                "id": 1,
                "name": "fury.jpg",
                "hash": "fd3d650cede946dd866aa1bb752323ab",
                "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
                "ext": ".jpg",
                "mime": "image/jpeg",
                "size": 88.22,
                "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
                "provider": "local",
                "provider_metadata": null,
                "created_at": "2020-02-07T10:56:55.799Z",
                "updated_at": "2020-02-07T10:56:55.799Z"
            }
        ],
        "actors": [
            {
                "id": 1,
                "Name": "Brad Pitt",
                "Description": "William Bradley Pitt is an American actor and film producer. He has received multiple awards, including two Golden Globe Awards for his acting, and an Academy Award and a Primetime Emmy Award as producer under his production company, Plan B Entertainment.",
                "created_at": "2020-02-07T12:14:29.664Z",
                "updated_at": "2020-02-07T12:14:29.664Z",
                "Thumbnail": [
                    {
                        "id": 2,
                        "name": "brad-pitt.jpg",
                        "hash": "64a9739501da43fa96297e77deba9127",
                        "sha256": "QU66_MQhGCofQCxcbtZ8qtjCbZFEwIS8aixAadYYH8I",
                        "ext": ".jpg",
                        "mime": "image/jpeg",
                        "size": 312.9,
                        "url": "/uploads/64a9739501da43fa96297e77deba9127.jpg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T12:14:29.744Z",
                        "updated_at": "2020-02-07T12:14:29.744Z"
                    }
                ]
            },
            {
                "id": 3,
                "Name": "Shia Labeouf",
                "Description": "Shia Saide LaBeouf is an American actor, performance artist, and filmmaker. He became known among younger audiences as Louis Stevens in the Disney Channel series Even Stevens, a role for which LaBeouf received a Young Artist Award nomination in 2001 and won a Daytime Emmy Award in 2003.",
                "created_at": "2020-02-07T12:33:57.216Z",
                "updated_at": "2020-02-07T12:33:57.216Z",
                "Thumbnail": [
                    {
                        "id": 4,
                        "name": "shia-lebeouf.jpeg",
                        "hash": "31bcdc49c8cb4d009506809eab66a146",
                        "sha256": "ooBzoBb0HHao-i8hy9c-UD41CzmAvOniLF10Vaa5Ezo",
                        "ext": ".jpeg",
                        "mime": "image/jpeg",
                        "size": 100.66,
                        "url": "/uploads/31bcdc49c8cb4d009506809eab66a146.jpeg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T12:33:57.275Z",
                        "updated_at": "2020-02-07T12:33:57.275Z"
                    }
                ]
            }
        ],
        "directors": [
            {
                "id": 2,
                "Name": "David Ayer",
                "Description": "David Ayer is an American film director, producer and screenwriter. He wrote Training Day, co-wrote The Fast and the Furious, and directed Harsh Times, Street Kings, End of Watch, Sabotage, Fury, Suicide Squad and Bright.",
                "created_at": "2020-02-07T12:39:27.058Z",
                "updated_at": "2020-02-07T12:39:27.058Z",
                "Thumbnail": []
            }
        ],
        "genres": [
            {
                "id": 1,
                "Title": "Action",
                "Description": null,
                "created_at": "2020-02-07T12:10:56.599Z",
                "updated_at": "2020-02-07T12:10:56.599Z"
            },
            {
                "id": 5,
                "Title": "War",
                "Description": null,
                "created_at": "2020-02-07T12:11:59.157Z",
                "updated_at": "2020-02-07T12:11:59.157Z"
            }
        ]
    },
    {
        "id": 2,
        "Title": "Salt",
        "Description": "CIA agent Evelyn Salt's life takes an ugly turn when she is accused of planning the assassination of the Russian president. However, she flees and sets out to prove her innocence.",
        "created_at": "2020-02-07T14:17:52.048Z",
        "updated_at": "2020-02-07T14:17:52.048Z",
        "Thumbnail": [
            {
                "id": 5,
                "name": "salt.jpeg",
                "hash": "a6e0dcd61f724e8481cae53a76f16803",
                "sha256": "eUSaONZSxatrDROoJJ1Zr1g81YFexNJtMk1Y8w_zRjo",
                "ext": ".jpeg",
                "mime": "image/jpeg",
                "size": 5.88,
                "url": "/uploads/a6e0dcd61f724e8481cae53a76f16803.jpeg",
                "provider": "local",
                "provider_metadata": null,
                "created_at": "2020-02-07T14:17:52.149Z",
                "updated_at": "2020-02-07T14:17:52.149Z"
            }
        ],
        "actors": [
            {
                "id": 2,
                "Name": "Angelina Jolie",
                "Description": "Angelina Jolie is an American actress, filmmaker, and humanitarian. The recipient of such accolades as an Academy Award and three Golden Globe Awards, she has been named Hollywood's highest-paid actress multiple times.",
                "created_at": "2020-02-07T12:29:52.506Z",
                "updated_at": "2020-02-07T12:29:52.506Z",
                "Thumbnail": [
                    {
                        "id": 3,
                        "name": "angelina-jolie.jpg",
                        "hash": "4a2244aa027948fb9f4980062219db34",
                        "sha256": "ebKbAgauLj0VSPvnTQMBbMUaMa7hO2zg5f1qKK2t5Kg",
                        "ext": ".jpg",
                        "mime": "image/jpeg",
                        "size": 778.6,
                        "url": "/uploads/4a2244aa027948fb9f4980062219db34.jpg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T12:29:52.579Z",
                        "updated_at": "2020-02-07T12:29:52.579Z"
                    }
                ]
            }
        ],
        "directors": [
            {
                "id": 1,
                "Name": "Phillip Noyce",
                "Description": "Phillip Noyce is an Australian director, producer, and screenwriter of film and television. Since 1977, he has directed over 19 feature films in various genres, including historical drama, thrillers, and action films. He has also directed the Jack Ryan adaptations Patriot Games and Clear and Present Danger and the 2014 adaptation of Lois Lowry's The Giver.",
                "created_at": "2020-02-07T12:37:55.677Z",
                "updated_at": "2020-02-07T12:37:55.677Z",
                "Thumbnail": []
            }
        ],
        "genres": [
            {
                "id": 1,
                "Title": "Action",
                "Description": null,
                "created_at": "2020-02-07T12:10:56.599Z",
                "updated_at": "2020-02-07T12:10:56.599Z"
            },
            {
                "id": 6,
                "Title": "Mystery",
                "Description": null,
                "created_at": "2020-02-07T12:28:10.558Z",
                "updated_at": "2020-02-07T12:28:10.558Z"
            },
            {
                "id": 4,
                "Title": "Thriller",
                "Description": null,
                "created_at": "2020-02-07T12:11:49.750Z",
                "updated_at": "2020-02-07T12:11:49.750Z"
            }
        ]
    }
]

http://localhost:1337/movies/1

{
    "id": 1,
    "Title": "Fury",
    "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
    "created_at": "2020-02-07T10:56:55.724Z",
    "updated_at": "2020-02-07T10:56:55.724Z",
    "Thumbnail": [
        {
            "id": 1,
            "name": "fury.jpg",
            "hash": "fd3d650cede946dd866aa1bb752323ab",
            "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
            "ext": ".jpg",
            "mime": "image/jpeg",
            "size": 88.22,
            "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
            "provider": "local",
            "provider_metadata": null,
            "created_at": "2020-02-07T10:56:55.799Z",
            "updated_at": "2020-02-07T10:56:55.799Z"
        }
    ],
    "actors": [
        {
            "id": 1,
            "Name": "Brad Pitt",
            "Description": "William Bradley Pitt is an American actor and film producer. He has received multiple awards, including two Golden Globe Awards for his acting, and an Academy Award and a Primetime Emmy Award as producer under his production company, Plan B Entertainment.",
            "created_at": "2020-02-07T12:14:29.664Z",
            "updated_at": "2020-02-07T12:14:29.664Z",
            "Thumbnail": [
                {
                    "id": 2,
                    "name": "brad-pitt.jpg",
                    "hash": "64a9739501da43fa96297e77deba9127",
                    "sha256": "QU66_MQhGCofQCxcbtZ8qtjCbZFEwIS8aixAadYYH8I",
                    "ext": ".jpg",
                    "mime": "image/jpeg",
                    "size": 312.9,
                    "url": "/uploads/64a9739501da43fa96297e77deba9127.jpg",
                    "provider": "local",
                    "provider_metadata": null,
                    "created_at": "2020-02-07T12:14:29.744Z",
                    "updated_at": "2020-02-07T12:14:29.744Z"
                }
            ]
        },
        {
            "id": 3,
            "Name": "Shia Labeouf",
            "Description": "Shia Saide LaBeouf is an American actor, performance artist, and filmmaker. He became known among younger audiences as Louis Stevens in the Disney Channel series Even Stevens, a role for which LaBeouf received a Young Artist Award nomination in 2001 and won a Daytime Emmy Award in 2003.",
            "created_at": "2020-02-07T12:33:57.216Z",
            "updated_at": "2020-02-07T12:33:57.216Z",
            "Thumbnail": [
                {
                    "id": 4,
                    "name": "shia-lebeouf.jpeg",
                    "hash": "31bcdc49c8cb4d009506809eab66a146",
                    "sha256": "ooBzoBb0HHao-i8hy9c-UD41CzmAvOniLF10Vaa5Ezo",
                    "ext": ".jpeg",
                    "mime": "image/jpeg",
                    "size": 100.66,
                    "url": "/uploads/31bcdc49c8cb4d009506809eab66a146.jpeg",
                    "provider": "local",
                    "provider_metadata": null,
                    "created_at": "2020-02-07T12:33:57.275Z",
                    "updated_at": "2020-02-07T12:33:57.275Z"
                }
            ]
        }
    ],
    "directors": [
        {
            "id": 2,
            "Name": "David Ayer",
            "Description": "David Ayer is an American film director, producer and screenwriter. He wrote Training Day, co-wrote The Fast and the Furious, and directed Harsh Times, Street Kings, End of Watch, Sabotage, Fury, Suicide Squad and Bright.",
            "created_at": "2020-02-07T12:39:27.058Z",
            "updated_at": "2020-02-07T12:39:27.058Z",
            "Thumbnail": []
        }
    ],
    "genres": [
        {
            "id": 1,
            "Title": "Action",
            "Description": null,
            "created_at": "2020-02-07T12:10:56.599Z",
            "updated_at": "2020-02-07T12:10:56.599Z"
        },
        {
            "id": 5,
            "Title": "War",
            "Description": null,
            "created_at": "2020-02-07T12:11:59.157Z",
            "updated_at": "2020-02-07T12:11:59.157Z"
        }
    ]
}

http://localhost:1337/genres/

http://localhost:1337/genres/1

{
    "id": 1,
    "Title": "Action",
    "Description": null,
    "created_at": "2020-02-07T12:10:56.599Z",
    "updated_at": "2020-02-07T12:10:56.599Z",
    "movies": [
        {
            "id": 1,
            "Title": "Fury",
            "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
            "created_at": "2020-02-07T10:56:55.724Z",
            "updated_at": "2020-02-07T10:56:55.724Z",
            "Thumbnail": [
                {
                    "id": 1,
                    "name": "fury.jpg",
                    "hash": "fd3d650cede946dd866aa1bb752323ab",
                    "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
                    "ext": ".jpg",
                    "mime": "image/jpeg",
                    "size": 88.22,
                    "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
                    "provider": "local",
                    "provider_metadata": null,
                    "created_at": "2020-02-07T10:56:55.799Z",
                    "updated_at": "2020-02-07T10:56:55.799Z"
                }
            ]
        },
        {
            "id": 2,
            "Title": "Salt",
            "Description": "CIA agent Evelyn Salt's life takes an ugly turn when she is accused of planning the assassination of the Russian president. However, she flees and sets out to prove her innocence.",
            "created_at": "2020-02-07T14:17:52.048Z",
            "updated_at": "2020-02-07T14:17:52.048Z",
            "Thumbnail": [
                {
                    "id": 5,
                    "name": "salt.jpeg",
                    "hash": "a6e0dcd61f724e8481cae53a76f16803",
                    "sha256": "eUSaONZSxatrDROoJJ1Zr1g81YFexNJtMk1Y8w_zRjo",
                    "ext": ".jpeg",
                    "mime": "image/jpeg",
                    "size": 5.88,
                    "url": "/uploads/a6e0dcd61f724e8481cae53a76f16803.jpeg",
                    "provider": "local",
                    "provider_metadata": null,
                    "created_at": "2020-02-07T14:17:52.149Z",
                    "updated_at": "2020-02-07T14:17:52.149Z"
                }
            ]
        }
    ]
}

http://localhost:1337/actors/

[
    {
        "id": 1,
        "Name": "Brad Pitt",
        "Description": "William Bradley Pitt is an American actor and film producer. He has received multiple awards, including two Golden Globe Awards for his acting, and an Academy Award and a Primetime Emmy Award as producer under his production company, Plan B Entertainment.",
        "created_at": "2020-02-07T12:14:29.664Z",
        "updated_at": "2020-02-07T12:14:29.664Z",
        "Thumbnail": [
            {
                "id": 2,
                "name": "brad-pitt.jpg",
                "hash": "64a9739501da43fa96297e77deba9127",
                "sha256": "QU66_MQhGCofQCxcbtZ8qtjCbZFEwIS8aixAadYYH8I",
                "ext": ".jpg",
                "mime": "image/jpeg",
                "size": 312.9,
                "url": "/uploads/64a9739501da43fa96297e77deba9127.jpg",
                "provider": "local",
                "provider_metadata": null,
                "created_at": "2020-02-07T12:14:29.744Z",
                "updated_at": "2020-02-07T12:14:29.744Z"
            }
        ],
        "movies": [
            {
                "id": 1,
                "Title": "Fury",
                "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
                "created_at": "2020-02-07T10:56:55.724Z",
                "updated_at": "2020-02-07T10:56:55.724Z",
                "Thumbnail": [
                    {
                        "id": 1,
                        "name": "fury.jpg",
                        "hash": "fd3d650cede946dd866aa1bb752323ab",
                        "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
                        "ext": ".jpg",
                        "mime": "image/jpeg",
                        "size": 88.22,
                        "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T10:56:55.799Z",
                        "updated_at": "2020-02-07T10:56:55.799Z"
                    }
                ]
            }
        ]
    },
    {
        "id": 2,
        "Name": "Angelina Jolie",
        "Description": "Angelina Jolie is an American actress, filmmaker, and humanitarian. The recipient of such accolades as an Academy Award and three Golden Globe Awards, she has been named Hollywood's highest-paid actress multiple times.",
        "created_at": "2020-02-07T12:29:52.506Z",
        "updated_at": "2020-02-07T12:29:52.506Z",
        "Thumbnail": [
            {
                "id": 3,
                "name": "angelina-jolie.jpg",
                "hash": "4a2244aa027948fb9f4980062219db34",
                "sha256": "ebKbAgauLj0VSPvnTQMBbMUaMa7hO2zg5f1qKK2t5Kg",
                "ext": ".jpg",
                "mime": "image/jpeg",
                "size": 778.6,
                "url": "/uploads/4a2244aa027948fb9f4980062219db34.jpg",
                "provider": "local",
                "provider_metadata": null,
                "created_at": "2020-02-07T12:29:52.579Z",
                "updated_at": "2020-02-07T12:29:52.579Z"
            }
        ],
        "movies": [
            {
                "id": 2,
                "Title": "Salt",
                "Description": "CIA agent Evelyn Salt's life takes an ugly turn when she is accused of planning the assassination of the Russian president. However, she flees and sets out to prove her innocence.",
                "created_at": "2020-02-07T14:17:52.048Z",
                "updated_at": "2020-02-07T14:17:52.048Z",
                "Thumbnail": [
                    {
                        "id": 5,
                        "name": "salt.jpeg",
                        "hash": "a6e0dcd61f724e8481cae53a76f16803",
                        "sha256": "eUSaONZSxatrDROoJJ1Zr1g81YFexNJtMk1Y8w_zRjo",
                        "ext": ".jpeg",
                        "mime": "image/jpeg",
                        "size": 5.88,
                        "url": "/uploads/a6e0dcd61f724e8481cae53a76f16803.jpeg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T14:17:52.149Z",
                        "updated_at": "2020-02-07T14:17:52.149Z"
                    }
                ]
            }
        ]
    },
    {
        "id": 3,
        "Name": "Shia Labeouf",
        "Description": "Shia Saide LaBeouf is an American actor, performance artist, and filmmaker. He became known among younger audiences as Louis Stevens in the Disney Channel series Even Stevens, a role for which LaBeouf received a Young Artist Award nomination in 2001 and won a Daytime Emmy Award in 2003.",
        "created_at": "2020-02-07T12:33:57.216Z",
        "updated_at": "2020-02-07T12:33:57.216Z",
        "Thumbnail": [
            {
                "id": 4,
                "name": "shia-lebeouf.jpeg",
                "hash": "31bcdc49c8cb4d009506809eab66a146",
                "sha256": "ooBzoBb0HHao-i8hy9c-UD41CzmAvOniLF10Vaa5Ezo",
                "ext": ".jpeg",
                "mime": "image/jpeg",
                "size": 100.66,
                "url": "/uploads/31bcdc49c8cb4d009506809eab66a146.jpeg",
                "provider": "local",
                "provider_metadata": null,
                "created_at": "2020-02-07T12:33:57.275Z",
                "updated_at": "2020-02-07T12:33:57.275Z"
            }
        ],
        "movies": [
            {
                "id": 1,
                "Title": "Fury",
                "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
                "created_at": "2020-02-07T10:56:55.724Z",
                "updated_at": "2020-02-07T10:56:55.724Z",
                "Thumbnail": [
                    {
                        "id": 1,
                        "name": "fury.jpg",
                        "hash": "fd3d650cede946dd866aa1bb752323ab",
                        "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
                        "ext": ".jpg",
                        "mime": "image/jpeg",
                        "size": 88.22,
                        "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T10:56:55.799Z",
                        "updated_at": "2020-02-07T10:56:55.799Z"
                    }
                ]
            }
        ]
    }
]

http://localhost:1337/actors/1

{
    "id": 1,
    "Name": "Brad Pitt",
    "Description": "William Bradley Pitt is an American actor and film producer. He has received multiple awards, including two Golden Globe Awards for his acting, and an Academy Award and a Primetime Emmy Award as producer under his production company, Plan B Entertainment.",
    "created_at": "2020-02-07T12:14:29.664Z",
    "updated_at": "2020-02-07T12:14:29.664Z",
    "Thumbnail": [
        {
            "id": 2,
            "name": "brad-pitt.jpg",
            "hash": "64a9739501da43fa96297e77deba9127",
            "sha256": "QU66_MQhGCofQCxcbtZ8qtjCbZFEwIS8aixAadYYH8I",
            "ext": ".jpg",
            "mime": "image/jpeg",
            "size": 312.9,
            "url": "/uploads/64a9739501da43fa96297e77deba9127.jpg",
            "provider": "local",
            "provider_metadata": null,
            "created_at": "2020-02-07T12:14:29.744Z",
            "updated_at": "2020-02-07T12:14:29.744Z"
        }
    ],
    "movies": [
        {
            "id": 1,
            "Title": "Fury",
            "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
            "created_at": "2020-02-07T10:56:55.724Z",
            "updated_at": "2020-02-07T10:56:55.724Z",
            "Thumbnail": [
                {
                    "id": 1,
                    "name": "fury.jpg",
                    "hash": "fd3d650cede946dd866aa1bb752323ab",
                    "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
                    "ext": ".jpg",
                    "mime": "image/jpeg",
                    "size": 88.22,
                    "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
                    "provider": "local",
                    "provider_metadata": null,
                    "created_at": "2020-02-07T10:56:55.799Z",
                    "updated_at": "2020-02-07T10:56:55.799Z"
                }
            ]
        }
    ]
}

http://localhost:1337/directors/

[
    {
        "id": 1,
        "Name": "Phillip Noyce",
        "Description": "Phillip Noyce is an Australian director, producer, and screenwriter of film and television. Since 1977, he has directed over 19 feature films in various genres, including historical drama, thrillers, and action films. He has also directed the Jack Ryan adaptations Patriot Games and Clear and Present Danger and the 2014 adaptation of Lois Lowry's The Giver.",
        "created_at": "2020-02-07T12:37:55.677Z",
        "updated_at": "2020-02-07T12:37:55.677Z",
        "Thumbnail": [],
        "movies": [
            {
                "id": 2,
                "Title": "Salt",
                "Description": "CIA agent Evelyn Salt's life takes an ugly turn when she is accused of planning the assassination of the Russian president. However, she flees and sets out to prove her innocence.",
                "created_at": "2020-02-07T14:17:52.048Z",
                "updated_at": "2020-02-07T14:17:52.048Z",
                "Thumbnail": [
                    {
                        "id": 5,
                        "name": "salt.jpeg",
                        "hash": "a6e0dcd61f724e8481cae53a76f16803",
                        "sha256": "eUSaONZSxatrDROoJJ1Zr1g81YFexNJtMk1Y8w_zRjo",
                        "ext": ".jpeg",
                        "mime": "image/jpeg",
                        "size": 5.88,
                        "url": "/uploads/a6e0dcd61f724e8481cae53a76f16803.jpeg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T14:17:52.149Z",
                        "updated_at": "2020-02-07T14:17:52.149Z"
                    }
                ]
            }
        ]
    },
    {
        "id": 2,
        "Name": "David Ayer",
        "Description": "David Ayer is an American film director, producer and screenwriter. He wrote Training Day, co-wrote The Fast and the Furious, and directed Harsh Times, Street Kings, End of Watch, Sabotage, Fury, Suicide Squad and Bright.",
        "created_at": "2020-02-07T12:39:27.058Z",
        "updated_at": "2020-02-07T12:39:27.058Z",
        "Thumbnail": [],
        "movies": [
            {
                "id": 1,
                "Title": "Fury",
                "Description": "A grizzled tank commander makes tough decisions as he and his crew fight their way across Germany in April, 1945.",
                "created_at": "2020-02-07T10:56:55.724Z",
                "updated_at": "2020-02-07T10:56:55.724Z",
                "Thumbnail": [
                    {
                        "id": 1,
                        "name": "fury.jpg",
                        "hash": "fd3d650cede946dd866aa1bb752323ab",
                        "sha256": "sUNwNj4bdfXoKKMROBTwbMY6gBXIW8m5BR7PpVuAang",
                        "ext": ".jpg",
                        "mime": "image/jpeg",
                        "size": 88.22,
                        "url": "/uploads/fd3d650cede946dd866aa1bb752323ab.jpg",
                        "provider": "local",
                        "provider_metadata": null,
                        "created_at": "2020-02-07T10:56:55.799Z",
                        "updated_at": "2020-02-07T10:56:55.799Z"
                    }
                ]
            }
        ]
    }
]

http://localhost:1337/directors/1

{
    "id": 1,
    "Name": "Phillip Noyce",
    "Description": "Phillip Noyce is an Australian director, producer, and screenwriter of film and television. Since 1977, he has directed over 19 feature films in various genres, including historical drama, thrillers, and action films. He has also directed the Jack Ryan adaptations Patriot Games and Clear and Present Danger and the 2014 adaptation of Lois Lowry's The Giver.",
    "created_at": "2020-02-07T12:37:55.677Z",
    "updated_at": "2020-02-07T12:37:55.677Z",
    "Thumbnail": [],
    "movies": [
        {
            "id": 2,
            "Title": "Salt",
            "Description": "CIA agent Evelyn Salt's life takes an ugly turn when she is accused of planning the assassination of the Russian president. However, she flees and sets out to prove her innocence.",
            "created_at": "2020-02-07T14:17:52.048Z",
            "updated_at": "2020-02-07T14:17:52.048Z",
            "Thumbnail": [
                {
                    "id": 5,
                    "name": "salt.jpeg",
                    "hash": "a6e0dcd61f724e8481cae53a76f16803",
                    "sha256": "eUSaONZSxatrDROoJJ1Zr1g81YFexNJtMk1Y8w_zRjo",
                    "ext": ".jpeg",
                    "mime": "image/jpeg",
                    "size": 5.88,
                    "url": "/uploads/a6e0dcd61f724e8481cae53a76f16803.jpeg",
                    "provider": "local",
                    "provider_metadata": null,
                    "created_at": "2020-02-07T14:17:52.149Z",
                    "updated_at": "2020-02-07T14:17:52.149Z"
                }
            ]
        }
    ]
}

As you can see from all the API endpoints that was created by Strapi. They are all nested and include all the many to many relationships. This will be really useful when we want to work with the data from the frontend.

Conclusion

We have now created an Movie Database and API that is available for public consumption  in around 15 Minutes, form installation to production (locally).

I find that extremely intriguing as I have personally built many APIs before and I can assure you that the development time is not 15 minutes :D

Did You Enjoy the Tutorial?

Consider sending some love to Freddie the creator.

Comments (0)

You need to be logged in to comment..

Topics Mentioned in this Tutorial

API
3
0
4
API stands for Application Programming Interface and is a communication protocol or interface between part of a computer program or machines. APIs are used in web applications, operating systems, database systems, software libraries and computer hardware to facilitate connection between systems or abstracting underlying implementation and only exposing objects or actions that is needed for developers....
Headless CMS
1
0
0
A Headless CMS is a new type of content management system that focus on providing back-end functonalities only. Where most CMS handles everything from the backend to the frontend in a monolithic nature, a Headless CMS is fundamentaly diffrent. It focuses on providing a solid admin panel for managing content, and the generation of an API, be it REST, GraphQL or Some other API query language. With this approach you database of content can be shipped/fetched from any where. Meaning that you can use one codebase for you Web, Mobile, TV and IoT applications....
Strapi
3
0
0
Strapi is a headless CMS built with JavaScript and NodeJS that makes it really quick and easy to create a content rich REST or GraphQL API....
Web Development
1
0
97
Web Development is the process of building website and applications for the world wide web (www)....