Giter Club home page Giter Club logo

typescript-express-api's Introduction

Typescript ExpressJS API

Tech stack

  • Typescript
  • Node.js
  • ExpressJS
  • Testing
    • Jest
    • Supertest
  • Database
    • MySQL
  • Authentication
    • JWT

Steps to use the API

  1. Register using the /users/signup route.
  2. Grab the token and use it as the Authorization header to sign in.
  3. Sign in and uses /assets/ routes to add, delete, update or read assets. Note: Sign in tokens expire after 1 hour.

Endpoints

/users

  • POST /users/signup - Sign up a new user

    • Request body:
    {
      "email": "[email protected]",
      "password": "password"
    }
    
    • Response: 200 OK
    {
      "message": "New user added"
    }
    
    • Errors:
      • 400 Bad Request - If request body is invalid or missing fields
      • 500 Internal Server Error - If server encounters an error while signing up user
  • POST /users/signin - Sign in a user

    • Request body:
    {
      "email": "[email protected]",
      "password": "password"
    }
    
    • Response: 200 OK
    {
      "result": {
        "id": 1,
        "email": "[email protected]",
        "password": "$2b$10$w6jKTY6CQYceZiURRZQXYeI0NlLjxdCT1z4Tkq3BqPkkB0.lYFnhS"
      },
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
    

/assets

  • GET /assets/ - Retrieve all assets

    • Auth: Required
    • Response: 200 OK
    [
      {
        "category": "property",
        "amount": 50000
      },
      {
        "category": "stocks",
        "amount": 20000
      },
      ...
    ]
    
    • Errors:
      • 401 Unauthorized - If user is not authenticated
      • 500 Internal Server Error - If server encounters an error while retrieving assets
  • POST /assets/add - Add a new asset

    • Auth: Required
    • Request body:
    {
      "category": "savings",
      "amount": 10000
    }
    
    • Response: 202 Accepted
    {
      "message": "Asset added"
    }
    
    • Errors:
      • 401 Unauthorized - If user is not authenticated
      • 400 Bad Request - If request body is invalid or missing fields
      • 500 Internal Server Error - If server encounters an error while adding asset
  • PUT /assets/update - Update an asset

    • Auth: Required
    • Request parameters:
      • category: The category of the asset to be updated
      • amount: The new amount for the asset
    • Request body:
    {
      "category": "savings",
      "amount": 10000
    }
    
    • Response: 202 Accepted
    {
      "message": "Asset updated: {category}"
    }
    
    • Errors:
      • 401 Unauthorized - If user is not authenticated
      • 400 Bad Request - If query parameters are invalid or missing
      • 500 Internal Server Error - If server encounters an error while updating asset
  • DELETE /assets?category={category} - Delete an asset

    • Auth: Required
    • Request query parameters:
      • category: The category of the asset to be deleted
    • Response: 202 Accepted
    {
      "message": "Asset deleted: {category}"
    }
    
    • Errors:
      • 401 Unauthorized - If user is not authenticated
      • 400 Bad Request - If query parameters are invalid or missing
      • 500 Internal Server Error - If server encounters an error while deleting asset

Successful test

}

typescript-express-api's People

Contributors

rahulsm20 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.