Nodejs Boilerplate API

This is a boilerplate created with an initial folder structure to store config files, controllers, data, routes, handlers, models and utilities. Once cloned, the user can hit the ground running since where all files should be located is already specified. This package comes with error handling, authentication, security, model seeding and authorization logic already initialized.

Authentication 10

Contains routes dealing with authentication which include registration, login, logout, account details editing, profile picture editing and currently logged in user data viewing

Description

Register a new user and if successful get a token

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "name": "Robert", "surname": "Downery Jr.", "email": "robertdowneyjr@marvel.com", "password": "RobertDowneryJr1" }
Description

Login an existing user and get a token in return

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "email": "margaiwangara@app.com", "password": "MargaiWangara1" }
Description

Get the details of the currently logged in user

Headers
KeyValueDescription
Content-Typeapplication/json
AuthorizationBearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkZGNmNDJhMDQwZGZhMzBkYzQxZTFiYyIsImlhdCI6MTU3NDc2MTc2NSwiZXhwIjoxNTc3MzUzNzY1fQ.K_sCAD_FKcvGLH53DolCS5GN3vJIiFgGyuJbshHvtXo
Body
{ "email": "robertdowneyjr@marvel.com", "password": "RobertDowneryJr1" }
Description

Log out currently logged in user by setting cookie value to none and destroying after 10 seconds

Headers
KeyValueDescription
Content-Typeapplication/json
AuthorizationBearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkZGNmNDJhMDQwZGZhMzBkYzQxZTFiYyIsImlhdCI6MTU3NDc2MTc2NSwiZXhwIjoxNTc3MzUzNzY1fQ.K_sCAD_FKcvGLH53DolCS5GN3vJIiFgGyuJbshHvtXo
Body
{ "email": "robertdowneyjr@marvel.com", "password": "RobertDowneryJr1" }
Description

Update details for the currently logged in user. Requires authentication

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "name": "Sherlock", "surname": "Holmes" }
Description

Change the profile image for the currently logged in user. Requires authentication

Headers
KeyValueDescription
Content-Typeapplication/json
Body
KeyValueDescription
file
Description

Update password for the currently logged in user. Requires authentication and three fields oldPassword, password and confirmPassword

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "oldPassword": "RobertDowneryJr1", "password": "SherlockHolmes1", "confirmPassword": "SherlockHolmes1" }
Description

Sends an email with a token for password reset to the user email provided if found in the document and belonging to a user

Headers
KeyValueDescription
Content-Typeapplication/json
AuthorizationBearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkZGNmNDJhMDQwZGZhMzBkYzQxZTFiYyIsImlhdCI6MTU3NDc2MTc2NSwiZXhwIjoxNTc3MzUzNzY1fQ.K_sCAD_FKcvGLH53DolCS5GN3vJIiFgGyuJbshHvtXo
Body
{ "email": "robertdowneyjr@marvel.com" }
Description

Gets token sent to email from URL and checks authenticity in document then resets password if token provided matches

Headers
KeyValueDescription
Content-Typeapplication/json
AuthorizationBearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkZGNmNDJhMDQwZGZhMzBkYzQxZTFiYyIsImlhdCI6MTU3NDc2MTc2NSwiZXhwIjoxNTc3MzUzNzY1fQ.K_sCAD_FKcvGLH53DolCS5GN3vJIiFgGyuJbshHvtXo
Query
KeyValueDescription
tokena9496ca6f58848745a7bb616e5672d0320c83e01
Body
{ "password": "DowneyJr1" }
Description

Gets email sent to the user during registration for email confirmation and compares against existing token in document, changes confirmed option in document to true

Headers
KeyValueDescription
Content-Typeapplication/json
Query
KeyValueDescription
token73a7b2ff6ec16d5123f543882a24b7d55cdd5d6b
Body
{ "name": "Raymond", "surname": "Reddington", "email": "redreddingon@blacklist.com", "password": "ConciergeOfCrime1" }

Posts 5

CRUD operations for posts. CREATE, GET, UPDATE and DELETE posts related to a user.

Description

Get all posts existing in the posts collection, in addition, the users who created the posts are also displayed

Description

Get single post by Id and information of the user who created the post

Description

Create a new post. Authentication is required since the user id is associated each time a new post is created

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "title": "Post 10", "content": "Content for post 10" }
Description

Update an existing post by Id

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "content": "Content for post 10 as a test" }
Description

Delete an existing post by Id

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "content": "Content for post 10 as a test" }

Users 5

Routes enabling CRUD operations on users in the users document. This routes utilize the roleAuthorized middleware hence only users with an admin role can perform operations on users.

Description

Get all users in the users collection. Requires admin privileges

Description

Get single user details from the users collection

Description

Create a new user

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "name": "Nick", "surname": "Fury", "email": "fury@marvel.com", "password": "NicholasJ1" }
Description

Update user details using Id

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "name": "Nicholas J." }
Description

Delete all user details by Id

Headers
KeyValueDescription
Content-Typeapplication/json
Body
{ "name": "Nicholas J." }

Filtering 4

Perform different operations by passing data to the url query. Can be performed on the GET request of all routes. Includes select, sort, filter by (gt, lt, gte, lte) and pagination

Description

Select only needed fields, for example, this operation only selects the title of the posts

Query
KeyValueDescription
selecttitle
Description

Sort either in ascending or descending based on fields. By default, the sorting is done in descending order by the createdAt field

Query
KeyValueDescription
sort-title
Description

Limit the number of results to be displayed per page and also results at which page should be displayed

Query
KeyValueDescription
limit2
page2
Description

Filtering can be done using gt, gte, lt, lte or in

Query
KeyValueDescription
content[gt]1