https://github.com/rafaelmoraes003/blogs-api
CRUD API for blog production using MySQL database with Sequelize.
https://github.com/rafaelmoraes003/blogs-api
express http javascript jsonwebtoken mysql node nodejs orm sequelize
Last synced: 3 months ago
JSON representation
CRUD API for blog production using MySQL database with Sequelize.
- Host: GitHub
- URL: https://github.com/rafaelmoraes003/blogs-api
- Owner: rafaelmoraes003
- Created: 2022-08-26T22:15:51.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-14T02:49:50.000Z (over 3 years ago)
- Last Synced: 2025-03-21T10:52:46.090Z (over 1 year ago)
- Topics: express, http, javascript, jsonwebtoken, mysql, node, nodejs, orm, sequelize
- Language: JavaScript
- Homepage:
- Size: 260 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Blogs API
###
In this project an API and a database were created for the production of content for a blog.
The application was developed in Node.js using the Sequelize package with a MySQL database to make a CRUD of posts following the principles of REST.
In it, it is possible to access endpoints that bring information about users, publications and categories of publication themes, in addition to being possible to create new data about them, update them and delete them. los.
The objective of the project was to be able to use Sequelize to create, populate, perform read, create, update and delete operations in the database and create relationships between tables
To to guarantee the security and integrity of the application, the authentication and authorization of the endpoints were done through the JSON Web Token.
###
Technologies used
###
###
How to use the application
###
Clone the application using the `git clone` command. After that, enter the project folder using the `cd blogs-api` command and run the `npm install` command. After installation, use the `npm start` command and enter port 3000 in your browser.
###
About the database
- Delete the database
`npm run drop`
- Create the database and generate the tables
`npm run prestart`
- Insert data/populate tables
`npm run seed`
###
Endpoints
###
Login
| Method | Functionality | URL |
|---|---|---|
| `POST` | Login with an existing user | http://localhost:3001/login |
The object to login must have the following format:
```JavaScript
{
email: "username@email.com",
password: "123456"
}
```
###
User
| Method | Functionality | URL |
|---|---|---|
| `GET` | List all users | http://localhost:3001/user |
| `GET` | List a user based on its id | http://localhost:3001/user/:id |
| `POST` | Create a new user | http://localhost:3001/user |
| `DELETE` | Delete the user who owns the session | http://localhost:3001/user/ME |
The object to create a new user must have the following format:
```JavaScript
{
displayName: "username",
email: "username@email.com",
password: "123456",
image: /* image url for user profile */
}
```
###
Post
| Method | Functionality | URL |
|---|---|---|
| `GET` | List all posts | http://localhost:3001/post |
| `GET` | Lists the post (or posts) that have a certain term included in their title or content | http://localhost:3001/post/search?q |
| `GET` | List a post based on its id | http://localhost:3001/post/:id |
| `POST` | Create a new post | http://localhost:3001/post |
| `PUT` | Update an existing post based on its id if the user in session owns that post | http://localhost:3001/post/:id |
| `DELETE` | Delete a post based on its id if the user in session owns that post | http://localhost:3001/post/:id |
The object to create a new post must have the following format:
```JavaScript
{
title: "My Post",
content: "Women in Tech",
categoryIds: [2, 5],
}
```
###
Categories
| Method | Functionality | URL |
|---|---|---|
| `GET` | List all categories | http://localhost:3001/categories |
| `POST` | Create a new category | http://localhost:3001/categories |
The object to create a new category must have the following format:
```JavaScript
{
name: "Tech"
}
```
###
COMMENTS
All endpoints (`except` `POST` ( `/login` and `/user`) require authorization through `JWT`. To acquire this token, it is necessary to create a user or log in with an existing user and place this token in the Authorization header of the request.