Routes | HTTP | Headers | Body |
---|---|---|---|
/users/register | POST | None | name: string, email: string, password: string |
/users/login | POST | None | email: string, password: string |
/users/googleSignIn | POST | googleidtoken: string | None |
/users/user | GET | access_token: string | None |
Returns an access token.
-
URL
/users/register
-
Method:
POST
-
URL Params
None
-
Header Params
None
-
Data Params
name: string; email: string; password: string
-
Success Response:
-
Code: 201
Content:{ "message": "Registered as a user!", "user": { "_id": "5de61836a9b2f15a0417e25a", "name": "johndoe", "email": "$2a$07$738j0cnEzr...", "password": "foo", "__v": 0 }, "access_token": "eyJhbGciOiJIUzI..." }
-
-
Error Response:
- Code: 400 BAD REQUEST
Content: `{"messages": [ "Email address has already been used!", "Your password is too short! Its length must be beween 5-15 characters." ]
- Code: 400 BAD REQUEST
}`
Returns an access token.
-
URL
/users/login
-
Method:
POST
-
URL Params
None
-
Data Params
None
-
Data Params
email: string; password: string;
-
Success Response:
- Code: 200
Content:{ "message": "Successfully loged in!", "user": { "_id": "5de61836a9b2f15a0417e25a", "name": "johndoe", "email": "[email protected]", "password": "$2a$07$738j0cnEzruvXrWCrN...", "__v": 0 }, "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ..." }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "messages": [ "Wrong email/password!" ] }
- Code: 404 NOT FOUND
Returns an access token.
-
URL
/users/googleSignIn
-
Method:
POST
-
URL Params
None
-
Header Params
googleidtoken: string;
-
Data Params
None
-
Success Response:
-
Code: 201
Content:{ "message": "Successfully registered!", "access_token": "bar" }
OR
-
Code: 200
Content:{ "message": "Successfully logged in!", "access_token": "bar" }
-
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "messages": [ "Wrong email/password!" ] }
- Code: 404 NOT FOUND
Returns currently active user.
-
URL
/users/user
-
Method:
GET
-
URL Params
None
-
Header Params
access_token: string;
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "_id": "5de61836a9b2f15a0417e25a", "name": "johndoe", "email": "[email protected]", "password": "$2a$07$738j0cnEzruvXrWCrN61I...", "__v": 0 }
- Code: 200
-
Error Response:
- Code: 401 UNAUTHORIZED
Content:{ "messages": [ "Unauthorized access!" ] }
- Code: 401 UNAUTHORIZED
No. | Routes | HTTP | Headers | Body | Description |
---|---|---|---|---|---|
1. | /articles/upload-image | POST | access_token: string | image: file | Upload an image |
2. | /articles | GET | access_token: string | None | Fetch all articles in database |
3. | /articles | POST | access_token: string | title: string, content: string, featured_image: string, tags: array | Post an article |
4. | /articles/:id | GET | access_token: string | None | Fetch a single article |
5. | /articles/:id | PUT | access_token: string | title: string, content: string, featured_image: string, tags: array | Update an article |
6. | /articles/:id | DELETE | access_token: string | None | Delete an article |
7. | /articles/:id/tags | POST | access_token: string | content: string | Post a comment to an article |
Upload a single image file to the database.
-
URL
/articles/upload-single
-
Method:
POST
-
URL Params
None
-
Header Params
access_token: string
-
Data Params
image: file
-
Success Response:
- Code: 200
Content:{ "data": imageUrl }
- Code: 200
-
Error Response:
- Code: 500 INTERNAL SERVER ERROR
Content:{ "messages": [ "Upload image failed. Please try again!" ] }
- Code: 500 INTERNAL SERVER ERROR
Returns all articles from the database.
-
URL
/articles
-
Method:
GET
-
URL Params
None
-
Header Params
access_token: string
-
Data Params
None
-
Success Response:
- Code: 200
Content:[ { "message": "Successfully published an article!", "article": { "tags": [ "personal", "life" ], "comments": [], "_id": "5de636c9481fb67ee302b56d", "title": "Limbo", "content": "...", "featured_image": "...", "author": "5de61836a9b2f15a0417e25a", "createdAt": "2019-12-03T10:19:53.852Z", "updatedAt": "2019-12-03T10:19:53.852Z", "__v": 0 } }, {...} ]
- Code: 200
-
Error Response:
- Code: 500 INTERNAL SERVER ERROR
Content:{ "messages": [ "Failed to fetch articles. Please refresh the browser!" ] }
- Code: 500 INTERNAL SERVER ERROR
Create a new article.
-
URL
/articles
-
Method:
POST
-
URL Params
None
-
Header Params
access_token: string
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "message": "Successfully published an article!", "article": { "tags": [ "personal", "life" ], "comments": [], "_id": "5de636c9481fb67ee302b56d", "title": "Limbo", "content": "...", "featured_image": "...", "author": "5de61836a9b2f15a0417e25a", "createdAt": "2019-12-03T10:19:53.852Z", "updatedAt": "2019-12-03T10:19:53.852Z", "__v": 0 } }
- Code: 200
-
Error Response:
-
Code: 500 INTERNAL SERVER ERROR
Content:{ "messages": [ "Failed to submit the article. Please try again!" ] }
-
Code: 401 UNAUTHORIZED
Content:{ "messages": [ "Unauthorized access!" ] }
-
Code: 400 BAD REQUEST
Content:{ "messages": [ "Title should not be empty!", "Post should not be empty!" ] }
-
Fetch a specific article.
-
URL
/articles/:id
-
Method:
GET
-
URL Params
None
-
Header Params
access_token: string
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "article": {"foo": "bar"} }
- Code: 200
-
Error Response:
- Code: 500 INTERNAL SERVER ERROR
Content:{ "messages": [ "Failed to fetch the article. Please try again!" ] }
- Code: 500 INTERNAL SERVER ERROR
-
URL
PATCH /articles/:id
-
Headers
- access_token: string
-
Body
- [title: string],
- [content: string],
- [featured_image: string],
- [tags: array]
-
Success Response:
- Code: 200
Content:{ "message": "Updated an article!", "article": { "tags": [ "personal", "life" ], "comments": [], "_id": "5de63839e19dd501f0201cdd", "title": "Nobody Nobody", "content": "...", "featured_image": "...", "author": "5de63815e19dd501f0201cdc", "createdAt": "2019-12-03T10:26:01.521Z", "updatedAt": "2019-12-03T11:39:51.698Z", "__v": 0 } }
- Code: 200
-
Error Response:
- Code: 500 INTERNAL SERVER ERROR
Content:{ "messages": [ "Failed to update the article. Please try again!" ] }
- Code: 500 INTERNAL SERVER ERROR
-
URL
DELETE /articles/:id
-
Headers
access_token: string
-
Body
None
-
Success Response:
- Code: 200
Content:{ "message": "Deleted an article!", "article": { "tags": [ "personal", "life" ], "comments": [], "_id": "5de63839e19dd501f0201cdd", "title": "Nobody Nobody", "content": "...", "featured_image": "...", "author": "5de63815e19dd501f0201cdc", "createdAt": "2019-12-03T10:26:01.521Z", "updatedAt": "2019-12-03T11:39:51.698Z", "__v": 0 }
- Code: 200
} ```
-
Error Response:
- Code: 500 INTERNAL SERVER ERROR
Content:{ "messages": [ "Failed to delete the article. Please try again!" ] }
- Code: 500 INTERNAL SERVER ERROR
-
URL
POST /articles/:id/tags
-
Headers
- access_token: string
-
Body
- content: string
-
Success Response:
- Code: 200
Content:{ "message": "Posted a comment!", "comment": { "_id": "5de64783f1b0b11779a114c2", "content": "'Great article!'", "article": "5de63839e19dd501f0201cdd", "commenter": "5de63815e19dd501f0201cdc", "createdAt": "2019-12-03T11:31:15.534Z", "updatedAt": "2019-12-03T11:31:15.534Z", "__v": 0 } }
- Code: 200
-
Error Response:
- Code: 400 VALIDATION ERROR
Content:{ "messages": [ "Comment should not be empty!" ] }
- Code: 400 VALIDATION ERROR
}