DEPLOY: http://overflow.orvinsavero.com/
- route:
POST /register
- request:
- body:
{ name: 'dimitri' , email: 'dimitri@mail.com', password: 'secret' }
- body:
- response:
201
:{ _id: ObjectId(''), name: 'dimitri', email: 'dimitri@mail.com', password: 'HashedPassword' }
- error:
Validation Error
- Email is unique, so it is not allowed to have same email in database.
- Password is hashed with bcryptjs.
- route:
POST /login
- request:
- body
{ email: 'dimitri@mail.com', password: 'secret' }
- body
- response:
201
:{ token: '...' }
- error:
404 not found
Token is generated from JWT package.
- route:
POST /question
- request
- headers
{ token }
- decoded
{ id: _id }
- body
{ title, description, category }
- headers
- response
201
:{ _id, title, description, category, created_at, upvotes, downvotes, UserId }
- error:
Validation Error
Token is decoded via JWT to get UserId.
- route:
GET /question
- request
- headers
{ token }
- decoded
{ id: _id }
- query
search
myQuestion
- headers
- response
200
:{ _id, title, description, category, created_at, upvotes, downvotes, UserId }
- error:
500 internal server error
- Token is decoded via JWT to get UserId.
- Query, myQuestion, is used to find specific UserId.
- Query, search, is used to find specific question (from question id).
- route:
PATCH /question/:questionId
- request
- headers
{ token, access }
- decoded
{ id: _id }
- params
{ id: questionId }
- body
{ title, description, category, upvotes, downvotes }
- headers
- response
200
:{ _id, title, description, category, created_at, upvotes, downvotes, UserId }
- error:
401 not authorized
User can not update Question that does not belongs to his/her it is authorized in middleware.
- route:
DELETE /question/:questionId
- request
- headers
{ token }
- params
{ id: questionId }
- decoded
{ id: _id }
- headers
- response
200
:{ "n" : 1, "ok": 1, "deletedCount": 1 }
- error:
401 not authorized
User can not delete Question that does not belongs to his/her, it is authorized in middleware.
- route:
PATCH /question/upvote/:id
- request
- headers
{ token, access }
- params
{ id: questionId }
- decoded
{ id: _id }
- headers
- response
200
:{ _id, title, comment, created_at, upvotes, downvotes, QuestionId, UserId }
- error:
500 internal server error
- Upvote +1.
- Upvote again 0.
- If User is present in Downvote, Downvote will be removed then Upvoted +1.
- route:
PATCH /question/upvote/:id
- request
- headers
{ token, access }
- params
{ id: questionId }
- decoded
{ id: _id }
- headers
- response
200
:{ _id, title, comment, created_at, upvotes, downvotes, QuestionId, UserId }
- error:
500 internal server error
- Downvote +1.
- Downvote again 0.
- If User is present in Upvote, Upvote will be removed then Downvoted -1.
- route:
POST /answer/:questionId
- request
- headers
{ token }
- params
{ id: questionId }
- decoded
{ id: _id }
- body
{ title, comment }
- headers
- response
201
:{ _id, title, comment, created_at, upvotes, downvotes, QuestionId, UserId }
- error:
Validation Error
Token is decoded via JWT to get UserId.
- route:
GET /answer/:questionId
- request
- headers
{ token }
- decoded
{ id: _id }
- query
myAnswer
- headers
- response
200
:{ _id, title, comment, created_at, upvotes, downvotes, QuestionId, UserId, status }
- error:
500 internal server error
- Token is decoded via JWT to get UserId.
- Helper is used to get status, such as it is yours or other's answer.
- Query, myAnswer, is used to find specific UserId.
- route:
PATCH /answer/:id
- request
- headers
{ token, access }
- params
{ id: answerId }
- decoded
{ id: _id }
- body
{ title, comment }
- headers
- response
200
:{ _id, title, comment, created_at, upvotes, downvotes, QuestionId, UserId }
- error:
401 not authorized
User can not update Answer that does not belongs to his/her it is authorized in middleware.
- route:
DELETE /answer/:id
- request
- headers
{ token }
- decoded
{ id: _id }
- headers
- response
200
:{ "n" : 1, "ok": 1, "deletedCount": 1 }
- error:
401 not authorized
User can not delete Answer that does not belongs to his/her, it is authorized in middleware.
- route:
PATCH /answer/upvote/:id
- request
- headers
{ token, access }
- params
{ id: answerId }
- decoded
{ id: _id }
- headers
- response
200
:{ _id, title, comment, created_at, upvotes, downvotes, QuestionId, UserId }
- error:
500 internal server error
- Upvote +1.
- Upvote again 0.
- If User is present in Downvote, Downvote will be removed then Upvoted +1.
- route:
PATCH /answer/upvote/:id
- request
- headers
{ token, access }
- params
{ id: answerId }
- decoded
{ id: _id }
- headers
- response
200
:{ _id, title, comment, created_at, upvotes, downvotes, QuestionId, UserId }
- error:
500 internal server error
- Downvote +1.
- Downvote again 0.
- If User is present in Upvote, Upvote will be removed then Downvoted -1.