Git Product home page Git Product logo

nodejs-recruitment-task-die's Introduction

Dockerized nodejs API with microservices

Prerequisites

You need to have docker and docker-compose installed on your computer to run the service

Run locally

  1. Clone this repository
  2. Run from root dir
docker-compose up -d

Services at PORTS

  • auth service will start on port 3000
  • movie service will start on port 3001
  • mongodb will start on port 27018

To stop the service run

docker-compose down

Authorized users

The auth service defines two user accounts that you should use

  1. Basic user ( can only post up to 5 movies per month)
 username: 'basic-thomas'
 password: 'sR-_pcoow-27-6PAwCD8'
  1. Premium user (all capabilities approved)
username: 'premium-jim'
password: 'GBLtTyq3E_UNjFnpo9m6'

Token payload

Decoding the auth token will give you access to basic information about the user, including its role.

{
  "userId": 123,
  "name": "Basic Thomas",
  "role": "basic",
  "iat": 1606221838,
  "exp": 1606223638,
  "iss": "https://www.netguru.com/",
  "sub": "123"
}

Example request

To authorize user call the auth service using for example curl. We assume that the auth service is running of the default port 3000.

Request

curl --location --request POST '0.0.0.0:3000/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "basic-thomas",
    "password": "sR-_pcoow-27-6PAwCD8"
}'

Response

{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEyMywibmFtZSI6IkJhc2ljIFRob21hcyIsInJvbGUiOiJiYXNpYyIsImlhdCI6MTYwNjIyMTgzOCwiZXhwIjoxNjA2MjIzNjM4LCJpc3MiOiJodHRwczovL3d3dy5uZXRndXJ1LmNvbS8iLCJzdWIiOiIxMjMifQ.KjZ3zZM1lZa1SB8U-W65oQApSiC70ePdkQ7LbAhpUQg"
}

Movie Service

Base URL: http://localhost:3001/

POST

endpoint: http://localhost:3001/movies method: POST

payload:

{
	"title": "Primer"
}

headers:

Authorization: Bearer <token>

GET

endpoint: http://localhost:3001/movies method: GET

headers:

Authorization: Bearer <token>

nodejs-recruitment-task-die's People

Contributors

adrianandrearczyk avatar krzyurb avatar nachoet avatar paweldrozanski avatar yeremyash avatar zmijewski 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.