Giter VIP home page Giter VIP logo

microservices-rentstream's Introduction

Getting Started

Running the application

First you will need to install Docker (this was all tested using Docker Desktop for Windows).
Then, simply run docker-compose up --build at the root of the project.

Troubleshooting

Sometimes you will get an error saying that a service failed to connect to the database.
Running the command again usually fixes it.

Testing

Navigate to the /test directory and run npm i && npm run build && npm start.

Technical info

We use an express gateway in front of all other services to handle authentication. Since this is a prototype, creating users is handled directly using the admin endpoints provided by express gateway. In reality, another service would have to be created so we have more control.

Documentation

Service: Catalog

GET /catalog : lists all available movies.

GET /catalog/:id : get a movie by ID.

GET /catalog/:title : search movies by title.

Service: Renting (Authenticated)

GET /renting: lists the rentals of the authenticated user.

GET /renting/rent: rent a movie by ID for the authenticated user.
Body: {movieId: number}

POST /renting/price/:movieId: set the price for a movie.
Body: {price: number}

GET /renting/price/:movieId: get the price for a movie.

Service: Streaming (Authenticated)

GET /streaming/:movieId: attempt a stream a movie (for this prototype, simply returns whether or not the operation is allowed).
This will only succeed if the authenticated user has rented that movie in the past 30 days.

Usage

Creating a user

Users are managed by Express Gateway.

To create a new user:
Send a POST request to http://localhost:9876/users :

POST /users
Body: {
  "username": "[email protected]",
  "firstname": "Steve", 
  "lastname": "Brown", 
  "birthdate": "1984-11-01" 
}

Then, create credentials for your user :

POST /credentials
Body: {
  "consumerId": "[email protected]",
  "type": "basic-auth"
}

The server will generate a password, which will be given to you in the response.
Copy that password somewhere.
You are now ready to make your first API requests.

Authenticating

To test things out, you can try sending a request to the catalog endpoint:

GET http://localhost:8080/catalog
Headers: {
'Authorization': 'Basic dGVzdDFAdGVzdC5jb206NWM0NzcxMzgtNzlkNS00ZGVhLTk2MzktODhhNWFmN2I4YTAx'
}

The authorization key is made up of the username and password encoded in base64.
You can get it by simply running btoa("username:password") in a javascript console.
Example:

> btoa("[email protected]:5c477138-79d5-4dea-9639-88a5af7b8a01")
< "dGVzdDFAdGVzdC5jb206NWM0NzcxMzgtNzlkNS00ZGVhLTk2MzktODhhNWFmN2I4YTAx"

microservices-rentstream's People

Contributors

carodepourtales avatar kelianb avatar

Watchers

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