Skip to content

stenzr/BloggingAuthService

Repository files navigation

BloggingAuthService

A REST API service to expose endpoints that allow users to Register, Login and make authenticated Requests to acess the blog articles.

  1. An authservice REST API in Node JS:
  • Database: MongoDb
  • Backend: NodeJS and Express

to login/ authorize the user.

API endpoints allow users to:

  • Register
  • Log in

based on JWT tokens

  1. A Blogging Service REST API in Node JS:
  • Database: MongoDb
  • Backend: NodeJS and Express

API endpoints allow users to:

  • Read,
  • Write,
  • Update,
  • Delete Blogs,
  • search Blogs by Author Name.

Authors



Tech Stack

Server: Express
Language: JavaScript
Database: MongoDb




API Reference


Register a new user

  POST api/users/register
Parameter Type Description
username string Required. username to register
email string Required. email id of user
password string Required. password of the user
confirmPassword string Required. password of the user

Response codes

User Story Response code Type Response Message
New user enters correct details expects registration 200 success "Succesfully Registered"
User Enters an email which is already registered 400 failure "Email already exists, try login"
User leaves the name blank 400 failure "Name cannot be empty"
User leaves the e-mail blank 400 failure "E-mail cannot be empty"
User enters and invalid e-mail 400 failure "Email is invalid"
User leaves the password blank 400 failure "Password field is required"
User leaves the confirm password blank 400 failure "Confirm password field is required"
User Enters a password less than 8 characters 400 failure "Password must be at least 8 characters"
User enters different password, confirm password 400 failure "Passwords must match"

Sample Request

{
  "name": "Rohit Kumar",
  "email": "[email protected]",
  "password": "rohit_password1 ",
  "confirmPassword": "rohit_password1"
}

Sample Response

{
  "msg": "Succesfully Registered"
}

Login a user

  POST api/users/login
Parameter Type Description
email string Required. email id of user
password string Required. password of the user

Response codes

User Story Response code Type Response Message
New user enters correct details expects login 200 success "User successfully logged in"
User enters an email which is not registered 400 failure "Email not found"
User enters a wrong password 400 failure "Password Incorrect"
User leaves the e-mail blank 400 failure "E-mail cannot be empty"
User enters and invalid e-mail 400 failure "Email is invalid"
User leaves the password blank 400 failure "Password field is required"
User Enters a password less than 8 characters 400 failure "Password must be at least 8 characters"

Sample Request

{
  "email": "[email protected]",
  "password": "rohit_password1 "
}

Sample Response

{
  "success": true,
  "msg": "User successfully logged in",
  "token": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyMjMzZDMxNTUxNDc3ZmFiYjBlNzZhNCIsIm5hbWUiOiJSb2hpdCBLdW1hciIsImlhdCI6MTY0NjQ4MjM1NCwiZXhwIjoxNjc4MDM5MjgwfQ.N8BUmTS2w82E3ORX4n9tv21r8AT9TT5I3I9-K6KqzSM"
}



Build Details:



To build the project on your system


  • Open your terminal in the required directory

  • Clone the repository

  git clone [email protected]:stenzr/authService.git

  • CD to the project directory
  cd authService

  • Install the required modules
  npm install

  • Start server
  nodemon run start


  • The server starts on localhost:5000

  • Use Postman to send request to the endpoints


Releases

No releases published

Packages

No packages published