It is recommended to develop this project together with the StarWars Blog Reading List. Eventually, that front-end will integrate with the API you will develop in this project, and you will have a fully functional application with both front-end and back-end.
Today we are going to build an API to manage a blog (The StarWars Blog). Users of this blog will be able to list planets, characters, and add or remove favorites.
To allow users to do all this, we must follow these steps:
- Start by modeling the database: create a database and the necessary tables to store that information. You may have already done this in the StarWars DataModeling project in node/express.
- Create your endpoints using Express.
- Constantly test your endpoints with Postman.
Do not clone this repository because we are going to use a different template.
We recommend opening the express.js template
using a development environment like Codespaces (recommended). Alternatively, you can clone it on your local computer using the git clone
command.
These are the repositories you need to open or clone:
https://github.com/4GeeksAcademy/expressjs-rest-hello
⚠ If you work locally, you must have a database and Node.js, but if you use Codespaces or Gitpod, everything is already installed.
👉 Please follow these steps on how to start a coding project.
💡 Important: Remember to save and upload your code to GitHub by creating a new repository, updating the remote (
git remote set-url origin <your new url>
), and uploading the code to your new repository using theadd
,commit
, andpush
commands from the git terminal.
Create an API connected to a database and implement the following endpoints (very similar to SWAPI.dev or SWAPI.tech):
[GET] /people
Retrieve all people records from the database using Express.[GET] /people/:people_id
Show the information of a single character by its id, using route parameters in Express.[GET] /planets
Retrieve all planet records from the database.[GET] /planets/:planet_id
Show the information of a single planet by its id.
Additionally, create the following endpoints to manage users and their favorites:
-
[GET] /users
Retrieve all blog users from the database. -
[GET] /users/favorites
Retrieve all favorites that belong to the current user. -
[POST] /favorite/planet/:planet_id
Add a new favorite planet to the current user, where :planet_id represents the ID of the planet to be added. -
[POST] /favorite/people/:people_id
Add a new favorite character to the current user, where :people_id represents the ID of the character to be added. -
[DELETE] /favorite/planet/:planet_id
Remove a favorite planet from the current user using its id. -
[DELETE] /favorite/people/:people_id
Remove a favorite character from the current user using its id. -
Your current API does not have an authentication system implemented yet. Therefore, the only way to create users is directly in the database. Use tools like an admin panel or a database manager to manually add users.
Note: Here is an example in Postman: https://documenter.getpostman.com/view/2432393/TzRSgnTS#a4174b48-3fc8-46e3-bf82-19a08107666f
This exercise will allow you to practice the following skills and concepts:
- Building APIs using the REST standard (a.k.a: RESTful APIs).
- Building a database using the ORM called TypeORM.
- Using and understanding database migration systems with TypeORM's native migrations.
The following requirements are not necessary to complete the project successfully, but you can develop them to continue your learning if you feel confident enough.
+4
Create endpoints to add (POST), modify (PUT), and delete (DELETE) planets
and people
. This way, the entire database can be managed via API instead of relying on the admin.
This and other projects are used to learn to code by students of 4Geeks Academy Coding Bootcamp conducted by Alejandro Sánchez and many other contributors. Learn more about our Programming Courses to become a Full Stack Developer, or our Data Science Bootcamp.