Skip to content

In this project an API and a database were developed to produce content for a blog. A Node.js application using the sequelize package to do a CRUD of posts. Creating endpoints that are connected to the database following REST principles

Notifications You must be signed in to change notification settings

m4rcos-dev/BackEnd-Project-Blogs-API

Repository files navigation

🎉 Welcome to my blogs API project repository

swagger documetation blogs api

flag tools flag tools flag tools flag database flag orm

Project developed during the back-end module of the Trybe full-stack web development course.

In this project an API and a database were developed to produce content for a blog.

A Node.js application using the sequelize package to do a CRUD of posts. Creating endpoints that are connected to the database following REST principles

🔨 Project Resources

  • ✅EndPoint for user login, using the POST method.
  • ✅EndPoint for registering users, using the POST method.
  • ✅EndPoint for lists all registered users, using the GET method
  • ✅EndPoint for lists by id only a registered user, using the GET method
  • ✅EndPoint to delete logged in user, using the DELETE method
  • ✅EndPoint for post category registration, using the POST method.
  • ✅EndPoint for lists all categories of registered posts, using the GET method
  • ✅EndPoint for lists all registered posts, using the GET method
  • ✅EndPoint for lists by id just a registered post, using the GET method
  • ✅EndPoint for lists by query informed only a registered post that corresponds to the title or content of the post, using the GET method
  • ✅EndPoint for registering a new post, using the POST method.
  • ✅EndPoint to update an existing post, using the PUT method.
  • ✅EndPoint to delete an existing post, using the DELETE method
  • ✅To make a post, you need a user and a login, so the relationship between the user and post tables is worked on
  • ✅It is necessary to use categories for posts, thus working on the relationship between posts tables for categories and categories for posts

▶️ Running application

🐋 Running on Docker vs Locally

👉 With Docker

⚠️ Before starting, your docker-compose needs to be at version 1.29 or higher. See here or in the documetation how to install it. In the first article, you can replace where you are with 1.26.0 with 1.29.2.

ℹ️ Run the node and db services with the docker-compose up -d --build command.

  • Remember to stop mysql if you are using it locally on the default port (3306), or adapt it, if you want to use the application in containers;

  • These services will initialize a container named blogs_api and another named blogs_api_db;

  • From here you can run the blogs_api container via CLI or open it in VS Code;

ℹ️ Use the command docker exec -it blogs_api bash.

  • It will give you access to the interactive terminal of the container created by compose, which is running in the background.

ℹ️ Install dependencies [If any] with npm install. (Install inside the container)

  • ⚠️ Attention: If you choose to use Docker, ALL the commands available in package.json (npm start, npm test, npm run dev, ...) must be executed **INSIDE ** of the container, that is, in the terminal that appears after executing the docker exec command mentioned above.

  • ⚠️ Attention: The git inside the container is not configured with your credentials. Either commit outside the container, or set your git credentials inside the container.

  • ⚠️ Attention: Do not run the npm audit fix command! It updates several project dependencies, and this update causes conflicts.

  • Tip: The Remote - Containers extension is indicated so that you can develop your application in the Docker container directly in VS Code, as you do with your local files.


👉 Without Docker

ℹ️ Install dependencies [If any] with npm install

  • ⚠️ Attention: Do not run the npm audit fix command! It updates several project dependencies, and this update causes conflicts.

  • ✨ Tip: To run the project this way, you must have node installed on your computer.


🎲 ER and Entities Diagram

Entity-Relationship Diagram

der


Format of entities

  • A table called users, containing data with the following structure:

    id display_name email password image
    1 Brett Wiltshire [email protected] // tem quer ser único 123456 http://4.bp.blogspot.com/_YA50adQ-7vQ/S1gfR_6ufpI/AAAAAAAAAAk/1ErJGgRWZDg/S45/brett.png
  • A table called categories, containing data with the following structure:

    id name
    18 News
  • A table called blog_posts, containing data with the following structure:

    id title content user_id published updated
    21 Latest updates, August 1st The whole text for the blog post goes here in this key 14 // Foreign key, referencing the id of users 2011-08-01T19:58:00.000Z 2011-08-01T19:58:51.947Z
  • A table called PostCategories, containing a composite primary key using the two structure attributes:

    post_id category_id
    50 // Primary and foreign key, referencing the id of BlogPosts 20 // Primary and foreign key, referencing id from Categories

    The data above are fictitious, and are here only as an example



👀 Ready-made script tips
  • Delete the database:

    "drop": "npx sequelize-cli db:drop"
  • Create the database and generate the tables:

    "prestart": "npx sequelize-cli db:create && npx sequelize-cli db:migrate"
  • Insert data / Populate the table:

    "seed": "npx sequelize-cli db:seed:all"


🧔 Author

About

In this project an API and a database were developed to produce content for a blog. A Node.js application using the sequelize package to do a CRUD of posts. Creating endpoints that are connected to the database following REST principles

Topics

Resources

Stars

Watchers

Forks

Languages