Skip to content

mitali-m-mulgaonkar/Node.js-Accounts-REST-API

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js-Accounts-REST-API

This service is a boilerplate to start new applications. It provides a restful API for user accounts management.

Environment variables

This service uses enviroment variables to gather config information. You can for example edit your environment variables using the command:

sudo nano /etc/environment

This configuration you need to add is used to connect to database and for app setup and is as as follows:

export USRACCNT_DB_HOST=localhost
export USRACCNT_DB_PORT=3306
export USRACCNT_DB_NAME=my_app
export USRACCNT_DB_USER=my_app
export USRACCNT_DB_PASSWORD=my_app_password
export USRACCNT_PORT=3000
export USRACCNT_JWT_SECRET=you_must_change_this_value

General API Information

  • The base endpoint is: /v1/accounts
  • All endpoints return either a JSON object or array.
  • All time and timestamp related fields are in milliseconds.

HTTP Return Codes

  • HTTP 4XX return codes are used for malformed requests; the issue is on the sender's side.
  • HTTP 403 return code is used when invalid credentials are provided.
  • HTTP 5XX return codes are used for internal errors; the issue is on the service side.

Error Codes

Any endpoint can return an ERROR with a message for extended information.

Sample ERROR Payload:

{
  "message": "Invalid authorization header."
}

General Information on Endpoints

  • For GET endpoints, parameters must be sent as a query string.
  • For POST, PUT, and DELETE endpoints, the parameters must be sent as a request body with content type application/json.
  • Parameters may be sent in any order.

Endpoints

This service provides the following endpoints:

Method endpoint VERB Descripcion
account-info /v1/accounts GET Returns current account information based on a valid JWT token
account-info /v1/accounts PUT Updates user account based on a valid JWT token
check-token /v1/accounts GET Check authorization header for valid JWT token
login /v1/accounts POST Process login request
register /v1/accounts POST Register an account
status /v1/accounts GET Returns server status

Account Info GET

Returns current account information based on a valid JWT token

GET /v1/accounts/account-info

Parameters:

NONE

Response:

{
  "fullname": "User Name",
  "phone": "12345678910",
  "email": "address@email.com"
}

Account Info PUT

Updates user account based on a valid JWT token

PUT /v1/accounts/account-info

Request Body:

{
  "fullname": "User Name",
  "email": "address@emal.com",
  "phone": "12345678910"
}

Response:

NONE

Check token

Check authorization header for valid JWT token

GET /v1/accounts/check-token

Parameters:

NONE

Response:

{
  "serverTime": 1575435948,
  "iat": 1575430011,
  "exp": 1575516411
}

Login

Process login request

POST /v1/accounts/login

Request Body:

{
  "email": "address@emal.com",
  "password": "sha3(512)password"
}

Response:

{
  "fullname": "User Name",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZC..."
}

Register

Register an account

POST /v1/accounts/register

Request Body:

{
  "fullname": "User Name",
  "email": "address@emal.com",
  "phone": "12345678910",
  "password": "sha3(512)password"
}

Response:

NONE

Status

Returns server status

POST /v1/accounts/status

Request Body:

NONE

Response:

{
  "serverTime": 1576029283
  "version": "1.0",
  "endPoint": "/v1/accounts",
}

Dependencies

This service is a Node.js app. The npm modules (or packages) used are:

Contact information

About

Restful API for user accounts management.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%