Git Product home page Git Product logo

movie-api's Introduction

Movie API

Movie API is a microservice for creating and fetching movies. The application is written in the Nest.js and uses the MongoDB document database for data storage.

How to run for development

  1. Clone this repository and Auth API
  2. Go to Movie API directory.
cd movie-api
  1. Configure your local.env file
cp local.env .env
# fill the variables with your creativity :) 
  1. Run MongoDb:
docker-compose up mongodb
  1. Install dependencies
npm install
  1. Run application with:
npm run start:dev
  1. Go to Auth API repository, set up as in auth-api readme.
  2. Configure JWT_SECRET in .env files to be the same in both repositories
  3. Run application with:
docker-compose up

By default the service will start on port 4200

Now you can see this app in action!

  1. Generate token.
curl --location -X POST 'localhost:3000/auth' \
-H'Content-Type: application/json' \
-d '{
    "username": "basic-thomas",
    "password": "sR-_pcoow-27-6PAwCD8"
}'
  1. Copy the token to variable
token=yourToken
  1. Create some movie:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${token}" localhost:4200/movies -d '{"title": "Spiderman"}'
  1. Get your movies:
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer ${token}" localhost:4200/movies

You should see the Spiderman Movie!

How to run containerized app

  1. Go to Movie API directory.
  2. Configure your .env file
cp prod.env .env
# fill the variables with your creativity :) 
  1. Build docker image:
docker-compose build
  1. Run Movie API and MongoDb with:
docker-compose up

By default the service will start on port 8000

How to run tests

Movie API uses Jest and mongodb-memory-server for testing

  1. Go to Movie API directory.
  2. Configure your application, do it like above
  3. Run unit tests with:
export NODE_ENV=test npm run test
  1. Run e2e tests with:
export NODE_ENV=test npm run test:e2e

Documentation

Add Movie

Creates movie object with details using title provided by user

URL Method Data Params Headers
/movies POST { title: string } Authorization: Bearer <token>
  • Success Response:

    • Code: 200

      Content:

      {
        	"message": "movie has been created successfully",
        	"data": {
        		"_id": "600e11db526b730ac7d45fbd",
        		"title": "Spiderman",
        		"released": "N/A",
        		"genre": "Short",
        		"director": "Christian Davi",
        		"userId": 123,
        		"createdAt": "2021-01-25T00:33:31.767Z",
        		"updatedAt": "2021-01-25T00:33:31.767Z",
        		"__v": 0
        	}
      }
  • Error Response:

    • Code: 422 UNPROCESSABLE_ENTITY

      Content:

      {
         	"message": "limit of added movies on the basic account has been exceeded",
         	"statusCode": 422
      }
    • Code: 400 BAD_REQUEST

    Content: json { "message": "Movie not found!", "statusCode": 400 }

    OR

    • Code: 403 FORBIDDEN

      Content:

      {
      	"statusCode": 403,
      	"message": "invalid token | jwt must be provided | jwt expired | role is not supported", 
      	"error": "Forbidden"
      }

Get All Movies

Creates movie object with details using title provided by user

URL Method Data Params Headers
/movies GET {} Authorization: Bearer <token>
  • Success Response:

    • Code: 200

      Content:

        [
        	{
      		"_id": "600e1413526b730ac7d45fca",
      		"title": "Spiderman",
      		"released": "N/A",
      		"genre": "Short",
      		"director": "Christian Davi",
      		"userId": 123,
      		"createdAt": "2021-01-25T00:42:59.458Z",
      		"updatedAt": "2021-01-25T00:42:59.458Z",
      		"__v": 0
      	}
        ]
  • Error Response:

    • Code: 403 FORBIDDEN

      Content:

      {
      	"statusCode": 403,
      	"message": "invalid token | jwt must be provided | jwt expired | role is not supported", 
      	"error": "Forbidden"
      }

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.