A blog API using industry best practices to deliver great results
Clone the repository and create a .env file in root directory
$ git clone https://github.com/Antimaterium/webedia-blog-test.git
$ cd webedia-blog-test
$ cp .env.example .env
Then run
$ npm install
or
$ yarn install
Go into sentry.io and create a new express project
Copy the DSN and paste it into SENTRY_DSN inside the .env file.
Run project in development mode
$ npm run dev
or
$ yarn dev
You can use the dump (webedia.sql) in the root or run the migrations like bellow
run migrations with
$ node_modules/.bin/sequelize db:migrate
or
$ yarn sequelize db:migrate
Note: Make sure your postgres database is up
Run tests
$ npm run test
or
$ yarn test
Create Session (JWT Token)
POST localhost:3000/session
Create a JWT Token. Returns the author object and the token.
Field | Required |
---|---|
Y | |
password | Y |
POST localhost:3000/session
{
"email": "vitorafonso33@gmail.com",
"password": "123456"
}
{
"author": {
"id": 2,
"name": "vitor",
"email": "vitorafonso33@gmail.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNTY0NDA1ODM0LCJleHAiOjE1NjQ0MDk0MzR9.SyJLmOZJ1iQPb8kX9EsZsmkTA5Zqu1F8TvU_4IfgG_A"
}
List Authors
GET localhost:3000/author
Returns a list of Authors
page - Select current page for listing
limit - Set limit of Authors by page
GET localhost:3000/author?page=1&limit=20
[
{
"id": 1,
"name": "vitor",
"email": "vitorafonso133@gmail.com"
},
{
"id": 4,
"name": "Kailyn Hickle II",
"email": "Donna_Auer39@gmail.com"
},
{
"id": 8,
"name": "Micah Mills",
"email": "Zoie_Will83@hotmail.com"
}
]
Create Author
POST localhost:3000/author
Create a Author. Returns the newly-created object.
Field | Required |
---|---|
name | Y |
Y | |
password | Y |
POST localhost:3000/author
{
"name": "vitor",
"email": "vitorafonso33@gmail.com",
"password": "123456"
}
{
"id": 1,
"name": "vitor",
"email": "vitorafonso33@gmail.com"
}
Update Author
PUT localhost:3000/author
Update a Author. Returns the updated object.
Field | Required |
---|---|
author_id | Y |
Field | Required |
---|---|
name | Y |
Y |
PUT localhost:3000/author/:author_id
{
"name": "Other name",
"email": "other@email.com"
}
{
"email": "other@email.com",
"name": "Other name",
"id": "1"
}
Update Author
DELETE localhost:3000/author/:author_id
Delete a Author.
Field | Required |
---|---|
author_id | Y |
DELETE localhost:3000/author/1
Does not respond nothing, only status 200
If you have any questions, please feel free to contact me at vitorafonso33@gmail.com or by opening a pull request.