Giter Site home page Giter Site logo

omkar231098 / pioneer_assessment Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 75 KB

This project implements a secure authentication API using Node.js and Swagger, providing endpoints for user registration, login, logout, and a sample route for data retrieval. It includes token-based authentication and documentation through Swagger for easy API exploration.

Home Page: https://pioneer-assessment.onrender.com

JavaScript 100.00%
express-js logger mongoose nodejs

pioneer_assessment's Introduction

Authentication API with Node.js and Swagger

Setup

  1. Clone the repository to your local machine:

    git clone https://github.com/omkar231098/pioneer_assessment.git
  2. Install the dependencies:

    npm install
  3. Set up environment variables by creating a .env file and adding the following:

    SECRET_KEY=your_secret_key_here
    DATABASE_URL=your_mongodb_URL
    PORT=8500
    
  4. Start the server:

    npm run server

    The server should now be running on http://localhost:8500.

API Endpoints

User Registration

  • URL: /auth/register
  • Method: POST
  • Description: Register a new user.
  • Request Body:
    {
      "username": "johndoe",
      "password": "password123"
    }
  • Success Response:
    {
      "success": true,
      "message": "Registration successful! You can now log in."
    }
  • Error Response:
    {
      "success": false,
      "message": "User already exists. Please use a different username."
    }

User Login

  • URL: /auth/login
  • Method: POST
  • Description: Log in with username and password.
  • Request Body:
    {
      "username": "johndoe",
      "password": "password123"
    }
  • Success Response:
    {
      "status": true,
      "message": "Successfully logged in",
      "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
    }
  • Error Response:
    {
      "status": false,
      "message": "Incorrect Password"
    }

User Logout

  • URL: /auth/logout
  • Method: POST
  • Description: Log out the user and blacklist the token.
  • Success Response:
    Logged out successfully
    
  • Error Response:
    Server error
    

Sample Route

  • URL: /gethello
  • Method: GET
  • Description: Sample route to return a hello message.
  • Request Headers:
    Authorization: your_access_token_here
    
  • Success Response:
    {
      "message": "Hello, World!"
    }
  • Error Response:
    {
      "error": "Internal Server Error"
    }

Swagger Documentation

Swagger documentation for the API endpoints is available at http://localhost:8500/documentations when the server is running. You can use Swagger UI or a similar tool to interactively explore and test the API.

Deployed Swagger Documentation https://pioneer-assessment.onrender.com/documentations

License

This project is licensed under the MIT License - see the LICENSE file for details.

pioneer_assessment's People

Contributors

omkar231098 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.