Project Description • Learning • Requirements • Stacks • How to run the application
Descrição do Projeto • Aprendizado • Requisitos • Tecnologias Utilizadas • Rodar a Aplicação
I created this BackEnd project during my learning period at Trybe, where I developed an API and a database for content production for a blog.
This is a NodeJS application that uses the Sequelize package to perform CRUD operations on posts.
- Development of endpoints connected to the database following REST principles
- ✅ Create migrations for the entities
User,Categories,BlogPostsandPostCategories - ✅ Create the
Usermodel insrc/database/models/user.jswith defined properties - ✅ Create the
POST /loginendpoint - ✅ Create the
POST /userendpoint - ✅ Create the
GET /userendpoint - ✅ Create the
GET /user/:idendpoint - ✅ Create the
Categorymodel insrc/database/models/category.jswith defined properties - ✅ Create the
POST /categoriesendpoint - ✅ Create the
GET /categoriesendpoint - ✅ Create the
BlogPostmodel insrc/database/models/blogPost.jswith defined properties and associations - ✅ Create the
PostCategorymodel insrc/database/models/postCategory.jswith defined properties and associations - ✅ Create the
GET /postendpoint - ❌ Create the
POST /postendpoint - ❌ Create the
GET post/:idendpoint - ❌ Create the
PUT /post/:idendpoint - ❌ Create the
DELETE post/:idendpoint - ❌ Create the
DELETE /user/meendpoint - ❌ Create the
GET post/search?q=:searchTermendpoint
Note: In some projects, certain requirements were not completed due to the accelerated dynamics of the course, not because I didn't know how to do them. At the time, I just needed a little more time. I haven't decided yet whether to leave it this way to demonstrate my progress during my learning or to complete the missing requirements from the course projects. Feedback is welcome.
- Docker
- Express
- MySQL
- Node.js
- MySQL must be running on your machine
⚠️ If you are on Windows, stop Windows' MySQL, as it will use MySQL from your Linux distro via WSL2 - Clone the repository:
git clone git@github.com:prtpj1/project-blogs-api.git - Access the project folder:
cd project-blogs-api - Install dependencies:
npm install - Create the ".env" file at the root of the project with the following data:
HOSTNAME='localhost'
MYSQL_PORT='3306'
MYSQL_DB_NAME='blogs-api'
MYSQL_USER='root'
MYSQL_PASSWORD='your-mysql-password'
JWT_SECRET='secret'
- Create the database and migrations:
npm run prestart - Populate the database:
npm run seed - In the terminal, start the application:
npm start
With the project running, you can test the routes by clicking on the Swagger link.
- Open the route
POST/user/and click theTry it outbutton
-
Fill in the fields with the new user data (you don't need to use your real data)
-
Click the
Executebutton
- If everything went well, your user was created, you will see the
201code and the authorization token was generated.
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkIjo4LCJkaXNwbGF5TmFtZSI6IkZ1bGFubyBkYSBTaWx2YSIsImVtYWlsIjoiZnVsYW5vQGdtYWlsLmNvbSIsInBhc3N3b3JkIjoiJDJiJDEwJGh2elo2elE3eEtDLk1PZ2VKUjQ2RXV2Z3I2YmMyT2pLWnZkUnlNc2FrSUpISWMvN2VvUTEyIiwiaW1hZ2UiOiJ3d3cucGljdHVyZS5wbmcifSwiaWF0IjoxNzE4MzA5NDIwLCJleHAiOjE3MTgzOTU4MjB9.gRMp60cD1GSAZwGVaSsfSj2kVxt8_3ZydNvoCY3J22A"
}
If something goes wrong, the error code and message will be displayed below there (name too short, password too short or not numeric, etc...)

- Copy only the text between the quotes after
"token": - At the top of the screen, click the
Authorizebutton, inValuepaste the token text you copied and click theAuthorizebutton, then close the modal by clickingClose - Now you can access all other routes as they are authorized.
Note: If you have any difficulty with the instructions and want to provide feedback, send me a message
Fiz este projeto BackEnd durante meu período de aprendizagem na Trybe onde desenvolvi uma API e um banco de dados para a produção de conteúdo para um blog.
Esta é uma aplicação em NodeJS que usa o pacote sequelize para fazer um CRUD de posts.
- Desenvolvimento de endpoints que foram conectados ao banco de dados seguindo os princípios do REST
- ✅ Criar migrations para as entidades
User,Categories,BlogPostsePostCategories - ✅ Criar o modelo
Useremsrc/database/models/user.jscom as propriedades definidas - ✅ Criar o endpoint
POST /login - ✅ Criar o endpoint
POST /user - ✅ Criar o endpoint
GET /user - ✅ Criar o endpoint
GET /user/:id - ✅ Criar o modelo
Categoryemsrc/database/models/category.jscom as propriedades definidas - ✅ Criar o endpoint
POST /categories - ✅ Criar o endpoint
GET /categories - ✅ Criar o modelo
BlogPostemsrc/database/models/blogPost.jscom as propriedades e associações definidas - ✅ Criar o modelo
PostCategoryemsrc/database/models/postCategory.jscom as propriedades e associações definidas - ✅ Criar o endpoint
GET /post - ❌ Criar o endpoint
POST /post - ❌ Criar o endpoint
GET post/:id - ❌ Criar o endpoint
PUT /post/:id - ❌ Criar o endpoint
DELETE post/:id - ❌ Criar o endpoint
DELETE /user/me - ❌ Criar o endpoint
GET post/search?q=:searchTerm
OBS: Em alguns projetos alguns requisitos não foram feitos devido a dinamica acelerada do curso e não por eu não saber como fazê-los. Na época eu apenas precisaria de um pouco mais de tempo.
Ainda não decidi se é melhor deixar desta forma para demonstrar o meu progresso durante meu aprendizado ou se seria melhor completar os requisitos que ficaram faltando nos projetos do curso.
Feedbacks são bem vindos.
- Docker
- Express
- MySQL
- Node.js
- O MySQL precisa estar rodando na sua máquina
⚠️ Se estiver no Windows, pare o MySQL do Windows, pois usará o MySQL da sua distro linux através do WSL2 - Clone o repositório:
git clone git@github.com:prtpj1/project-blogs-api.git - Acesse a pasta do projeto:
cd project-blogs-api - Instale as dependências:
npm install - Crie o arquivo ".env" na raiz do projeto com os seguintes dados:
HOSTNAME='localhost'
MYSQL_PORT='3306'
MYSQL_DB_NAME='blogs-api'
MYSQL_USER='root'
MYSQL_PASSWORD='sua-senha-mysql'
JWT_SECRET='secret'
- Crie o banco de dados e as migrations:
npm run prestart - Popule o banco de dados:
npm run seed - No terminal inicie a aplicação:
npm start
Com o projeto rodando você poderá testar as rotas clicando no link do Swagger
- Abra a rota
POST/user/e clique no botãoTry it out
-
Preencha os campos com os dados do novo usuário (não precisam ser dados reais)
-
Clique no botão
Execute
- Se tudo correu bem, o seu usuário foi criado, você verá o código 201 e foi gerado o token de autorização.
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkIjo4LCJkaXNwbGF5TmFtZSI6IkZ1bGFubyBkYSBTaWx2YSIsImVtYWlsIjoiZnVsYW5vQGdtYWlsLmNvbSIsInBhc3N3b3JkIjoiJDJiJDEwJGh2elo2elE3eEtDLk1PZ2VKUjQ2RXV2Z3I2YmMyT2pLWnZkUnlNc2FrSUpISWMvN2VvUTEyIiwiaW1hZ2UiOiJ3d3cucGljdHVyZS5wbmcifSwiaWF0IjoxNzE4MzA5NDIwLCJleHAiOjE3MTgzOTU4MjB9.gRMp60cD1GSAZwGVaSsfSj2kVxt8_3ZydNvoCY3J22A"
}
Caso algo de errado, será exibido o código do erro e a mensagem de erro (nome muito curto, senha muito curta ou não numérica, etc...)

- Copie somente o texto que está entre aspas após
"token": - No topo da tela clique no botão
Authorize, emValuecole o texto do token que você copiou e clique no botãoAuthorizee feche o modal clicando emClose - Agora você pode acessar todas as outras rotas, pois já estão autorizadas.
OBS: Se tiver alguma dificuldade com as instruções e quiser dar um feedback me mande uma mensagem







