This README would normally document whatever steps are necessary to get the application up and running.
Use that docker-compose up
post request post '/user', parameters: {json body}, headers { "Content-Type": "application/json" }
User should make a post request with input json body to create new user and the api should return user information and the response will be like that output format
{
"user": {
"name": "Khaled",
"email": "khaled@example.com",
"password": "123456789",
"image": "1.jpg"
}
}
{
"token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJlbWFpbCI6ImtoYWxlZEBnbWFpbC5jb20iLCJwYXNzd29yZCI6IjEyMzQ1Njc4In0.-HZyS5KJyunBcDWsFZ2an0fBdFgl_8hs7kqjXSwDbg4",
"user": {
"id": 1,
"name": "khaled",
"email": "khaled@gmail.com",
"password_digest": "$2a$12$NGSoLi1A0U/mezM/f0Ja0OH/vuvpiipywBsh74f9N6ZsoBkU.uwaG",
"image": "1.jpg",
"created_at": "2021-01-29T23:26:37.999Z",
"updated_at": "2021-01-29T23:26:37.999Z"
}
}
post request post '/login', paramters: {json body}, headers { "Content-Type": "application/json" }
User should make a post request with input json body to login to the api and will return token back to use it for make any request for api
{
"user":
{
"email" : "khaled@gmail.com",
"password" : "12345678"
}
}
{
"token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJlbWFpbCI6ImtoYWxlZEBnbWFpbC5jb20iLCJwYXNzd29yZCI6IjEyMzQ1Njc4In0.-HZyS5KJyunBcDWsFZ2an0fBdFgl_8hs7kqjXSwDbg4"
}
delete request delete '/user/:user_id', headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
User should make a delete request with his token to delete his account from the system
if token doesn't match the right id won't allow to you delete that user
status code : 200 OK
post request post '/post', paramters: {json body}, headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To make new post you should have your JWT token and all post arrtributes: title, body and tags
{
"title":"add new post",
"body": "restful api for blogs application",
"tags": ["ruby" , "ruby on rails","api"]
}
{
"post": {
"id": 1,
"title": "add new post",
"body": "restful api for blogs application",
"tags": [
"ruby",
"ruby on rails",
"api"
],
"user_id": 1,
"created_at": "2021-01-29T22:51:28.788Z",
"updated_at": "2021-01-29T22:51:28.788Z"
},
"comments": []
}
patch request patch '/post/:post_id', paramters: {json body}, headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To update an existing post you should have your JWT token ,post id and updated arrtributes: title, body or tags
If you not owner of that post api won't allow to you update that post
{
"title":"update post",
"body": "restful api for blogs application",
"tags": ["ruby" , "ruby on rails","api"]
}
{
"post": {
"id": 1,
"title": "update post",
"body": "restful api for blogs application",
"tags": [
"ruby",
"ruby on rails",
"api"
],
"user_id": 1,
"created_at": "2021-01-29T22:51:28.788Z",
"updated_at": "2021-01-29T22:51:28.788Z"
},
"comments": []
}
get request get '/post/:post_id', headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To get an existing post you should have your JWT token and post id
{
"post": {
"id": 1,
"title": "update post",
"body": "restful api for blogs application",
"tags": [
"ruby",
"ruby on rails",
"api"
],
"user_id": 1,
"created_at": "2021-01-29T22:51:28.788Z",
"updated_at": "2021-01-29T22:51:28.788Z"
},
"comments": []
}
delete request delete '/post/:post_id', headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To delete an existing post you should have your JWT token and post id
If you not owner of that post api won't allow to you delete that post
status code : 200 OK
post request post '/post/:post_id/comment', paramters : {json body}, headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To make new comment on a post you should have your JWT token and all comment arrtributes: body
{
"body": "restful api for blogs application",
}
{
"id": 1,
"body": "restful api for blogs application",
"user_id": 1,
"post_id": 1,
"created_at": "2021-01-29T22:52:06.341Z",
"updated_at": "2021-01-29T22:52:06.341Z"
}
patch request patch '/post/:post_id/comment/:comment_id', paramters : {json body}, headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To update an existing comment on a post you should have your JWT token, post id, comment id and updated arrtributes: body
If you are not owner of that comment api won't allow to you update that comment
{
"body": "update restful api for blogs application",
}
{
"id": 1,
"body": "update restful api for blogs application",
"user_id": 1,
"post_id": 1,
"created_at": "2021-01-29T22:52:06.341Z",
"updated_at": "2021-01-29T22:52:06.341Z"
}
get request get '/post/:post_id/comment/:comment_id', headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To get an existing comment you should have your JWT token ,post id and comment id
{
"id": 1,
"body": "restful api for blogs application",
"user_id": 1,
"post_id": 1,
"created_at": "2021-01-29T22:52:06.341Z",
"updated_at": "2021-01-29T22:52:06.341Z"
}
delete request delete '/post/:post_id/comment/:comment_id', headers { "Content-Type": "application/json" , "Authorization": "Bearer <user_token>" }
To delete an existing comment you should have your JWT token, post id and comment id
If you not owner of that comment api won't allow to you delete that comment
status code : 200 OK
- If you try to create new user and password less than 8 characters or invalid email
- Error Message will be like that
-
{ "email": [ "is invalid" ], "password": [ "is too short (minimum is 8 characters)" ] }
-
- Error Message will be like that
- If you try to create a new post with missing arrtributes
- Error Message will be like that
-
{ "message": { "title": [ "can't be blank" ] } }
-
- Error Message will be like that
- If you try to create a new comment with empty body
- Error Message will be like that
-
{ "message": { "body": [ "can't be blank" ] } }
-
- Error Message will be like that
{
"post": {
"id": 1,
"title": "blog api",
"body": "restful api for books application",
"tags": [
"ruby",
"ruby on rails",
"api"
],
"user_id": 1,
"created_at": "2021-01-29T22:51:28.788Z",
"updated_at": "2021-01-29T22:51:28.788Z"
},
"comments": [
{
"id": 1,
"body": "that is useful api",
"user_id": 2,
"post_id": 1,
"created_at": "2021-01-29T22:52:06.341Z",
"updated_at": "2021-01-29T22:52:06.341Z"
}
]
}