Clique
aqui para ver a versão em Português.
The project consists of a simple API for authors and their posts. It allows actions such as creating, listing, editing, and deleting posts.
Posts can be marked as published or not.
Node.js
Express
TypeScript
Prisma ORM
GET
/users
(returns all users)
None
http code
content-type
response
200
application/json
JSON containing all users
curl - X GET - H "Content-Type: application/json" http://localhost:4000/users
GET
/posts
(returns all posts)
None
http code
content-type
response
200
application/json
JSON containing all blog posts
curl - X GET - H "Content-Type: application/json" http://localhost:4000/posts
GET
/post/{id}
(returns the post with the specified ID)
name
type
data type
description
id
required
string
The unique identifier of the post
http code
content-type
response
200
application/json
JSON containing the post with the specified ID
curl - X GET - H "Content-Type: application/json" http://localhost:4000/post/id
Creating a New User or Post
POST
/post
(creates a new post)
name
type
data type
description
title
required
string
Title of the post
body
required
string
Content of the post
author
required
int
Unique identifier of the post author
http code
content-type
response
201
text/plain;charset=UTF-8
Post created successfully
400
application/json
{"code":"400","message":"Bad Request"}
405
text/html;charset=utf-8
None
curl - X POST - H "Content-Type: application/json" -- data @post . json http ://localhost:4000/posts
POST
/users
(creates a new user)
name
type
data type
description
email
required
string
User's email
name
required
string
User's name
age
optional
int
User's age
http code
content-type
response
201
text/plain;charset=UTF-8
User created successfully
400
application/json
{"code":"400","message":"Bad Request"}
405
text/html;charset=utf-8
None
curl - X POST - H "Content-Type: application/json" -- data @user . json http ://localhost:4000/users
PUT
/post/{id}
(edits a post)
name
type
data type
description
id
required
int
Unique identifier of the post
http code
content-type
response
200
text/plain;charset=UTF-8
Returns the edited post
400
application/json
{"code":"400","message":"Bad Request"}
405
text/html;charset=utf-8
None
curl - X PUT - H "Content-Type: application/json" -- data @put . json http ://localhost:4000/post/id
DELETE
/post/{id}
(deletes a post)
name
type
data type
description
id
required
int
Unique identifier of the post
http code
content-type
response
200
text/plain;charset=UTF-8
Returns a status true
400
application/json
{"code":"400","message":"Bad Request"}
405
text/html;charset=utf-8
None
curl - X DELETE - H "Content-Type: application/json" http://localhost:4000/post/id
$ git clone https://github.com/luc-ribeiro/blog-api-node.git
Install the dependencies:
# with npm
$ npm install
# with yarn
$ yarn install
# with npm
$ npm start
# with yarn
$ yarn start
Access the project at localhost:[PORT DEFINED IN THE .ENV FILE]