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.
- Clone this repository and Auth API
- Go to Movie API directory.
cd movie-api
- Configure your local.env file
cp local.env .env
# fill the variables with your creativity :)
- Run MongoDb:
docker-compose up mongodb
- Install dependencies
npm install
- Run application with:
npm run start:dev
- Go to Auth API repository, set up as in auth-api readme.
- Configure JWT_SECRET in .env files to be the same in both repositories
- Run application with:
docker-compose up
By default the service will start on port 4200
- Generate token.
curl --location -X POST 'localhost:3000/auth' \
-H'Content-Type: application/json' \
-d '{
"username": "basic-thomas",
"password": "sR-_pcoow-27-6PAwCD8"
}'
- Copy the token to variable
token=yourToken
- Create some movie:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${token}" localhost:4200/movies -d '{"title": "Spiderman"}'
- Get your movies:
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer ${token}" localhost:4200/movies
You should see the Spiderman Movie!
- Go to Movie API directory.
- Configure your .env file
cp prod.env .env
# fill the variables with your creativity :)
- Build docker image:
docker-compose build
- Run Movie API and MongoDb with:
docker-compose up
By default the service will start on port 8000
Movie API uses Jest and mongodb-memory-server for testing
- Go to Movie API directory.
- Configure your application, do it like above
- Run unit tests with:
export NODE_ENV=test npm run test
- Run e2e tests with:
export NODE_ENV=test npm run test:e2e
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" }
-
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" }
-