Code Monkey home page Code Monkey logo

node-services's Introduction

Node.js Challenge

How to run the project


Run the next commands in order to start the services:

  1. cp .env.sample .env
  2. docker-compose up -d

Now, api-service will be running on your local port 3000 and stock-service will be running on your local port 3001.

API Service


Register new user

POST /auth/register

Body parameters

{
    "email": "[email protected]",
    "password": "mySecurePassword",
    "role": "admin" | "user"
}

Response example

{
    "email": "[email protected]",
    "role": "admin" | "user"
}

Login

POST /auth/login

Body parameters

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

Response example

{
    "token": {
        "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImIxOWM1MDMyLWIzN2QtNDU5ZC1iZTY5LTIzNWFlNTNmMjAzZCIsInJvbGVzIjpbImFkbWluIl0sImlhdCI6MTY3Mzg4MDc0MCwiZXhwIjoxNjczOTY3MTQwfQ.IQeS_VSO0lbBkZzNCvFZvbnSDTnCOKiQzG5OSRPN7WE",
        "expiresIn": 86400,
        "tokenType": "Bearer",
        "roles": [
            "admin"
        ]
    },
    "user": {
      "email": "[email protected]"
    }
}

Get stock

GET /stock?stock_code=${myStockCode}

Headers

{
  Authorization: "Bearer ${myAccessToken}"
}

Use accessToken value, obtained from login response.

Response example

{
    "name": "STOCK NAME",
    "symbol": "STOCK.SYMBOL",
    "open": 2.35,
    "high": 2.35,
    "low": 2.34,
    "close": 2.345
}

Get stock history

GET /stock/history?limit=${maxResultsPerQuery}&page=${numberOfPage}

Headers

{
    Authorization: "Bearer ${myAccessToken}"
}

Use accessToken value, obtained from login response.

Response example

{
  "data": [
    {
      "name": "STOCK NAME",
      "symbol": "STOCK.SYMBOL",
      "open": 2.35,
      "high": 2.35,
      "low": 2.34,
      "close": 2.345
    }
  ],
  "pagination": {
    "total": 1,
    "limit": 25,
    "page": 1,
    "pages": 1
  }
}

Get stats

GET /stock/stats

Headers

{
  Authorization: "Bearer ${myAccessToken}"
}

Use accessToken value, obtained from login response.

Response example

[
  {
    "stock": "STOCK.SYMBOL",
    "times_requested": 1
  }
]

NOTE: Only admins can access this endpoint.

node-services's People

Contributors

sebastian-coding 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.