Simple REST API created for recruitment process.
Demo: https://simple-rest-api-movies.herokuapp.com/movies
- POST
/movies
- GET
/movies
- POST
/comments
- GET
/comments
- MySQL
- Node.js & NPM
- OMDb API Key
CREATE DATABASE <db name>;
CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON *.* TO '<username>'@'localhost';
$ npm i
Visit this link and follow the instructions.
Open a file editor (I like vim):
$ vi .env
and paste the following content:
PORT=3030
DB_HOST=localhost
DB_PORT=3306
DB_USER=<your db username>
DB_PASSWORD=<your db password>
DB_NAME=<your db name>
API_URL=http://www.omdbapi.com/
API_KEY=<your omdb api key>
$ npm start
$ npm test
or with coverage
$ npm run test:coverage
Using this API is very simple. Here is a short documentation of the available endpoints:
Add a movie to the database
body:
{
title: 'Harry Potter', // string; required
type: 'movie', // one of ['movie', 'series', 'episode']; optional
year: 2011, // number; optional
plot: 'short' // one of ['short', 'full']; optional
}
response:
{
"movieId": 1,
"imdbId": "tt1201607",
"title": "Harry Potter and the Deathly Hallows: Part 2",
"year": "2011",
"runtime": "130 min",
"genre": "Adventure, Drama, Fantasy, Mystery",
"director": "David Yates",
"plot": "Harry, Ron, and Hermione search for Voldemort's remaining Horcruxes in their effort to destroy the Dark Lord as the final battle rages on at Hogwarts.",
"poster": "https://m.media-amazon.com/images/M/MV5BMjIyZGU4YzUtNDkzYi00ZDRhLTljYzctYTMxMDQ4M2E0Y2YxXkEyXkFqcGdeQXVyNTIzOTk5ODM@._V1_SX300.jpg",
"website": "http://www.HarryPotter.com/",
"updatedAt": "2019-08-02T17:18:45.780Z",
"createdAt": "2019-08-02T17:18:45.780Z"
}
Get movies from the database
body:
no params required
response:
[
{
"movieId":1,
"imdbId":"tt1201607",
"title":"Harry Potter and the Deathly Hallows: Part 2",
"year":2011,
"runtime":"130 min",
"genre":"Adventure, Drama, Fantasy, Mystery",
"director":"David Yates",
"plot":"Harry, Ron, and Hermione search for Voldemort's remaining Horcruxes in their effort to destroy the Dark Lord as the final battle rages on at Hogwarts.",
"poster":"https://m.media-amazon.com/images/M/MV5BMjIyZGU4YzUtNDkzYi00ZDRhLTljYzctYTMxMDQ4M2E0Y2YxXkEyXkFqcGdeQXVyNTIzOTk5ODM@._V1_SX300.jpg",
"website":"http://www.HarryPotter.com/",
"createdAt":"2019-08-02T17:18:45.000Z",
"updatedAt":"2019-08-02T17:18:45.000Z"
}
]
Add a comment to the movie
body:
{
movieId: 1, // number; required
userId: null, // number or null; optional
content: 'I am Iron Man', // string; min 10 chars; required
}
response:
{
"commentId": 1,
"content": "I am Iron Man",
"userId": null,
"updatedAt": "2019-08-02T17:24:25.638Z",
"createdAt": "2019-08-02T17:24:25.626Z",
"movie_id": 1
}
Get all comments
body:
no params required
response:
[
{
"commentId":1,
"content":"I am Iron Man",
"userId":null,
"createdAt":"2019-08-02T17:24:25.000Z",
"updatedAt":"2019-08-02T17:24:25.000Z",
"movie_id":1,
"Movie": {
"movieId":1,
"imdbId":"tt1201607",
"title":"Harry Potter and the Deathly Hallows: Part 2",
"year":2011,
"runtime":"130 min",
"genre":"Adventure, Drama, Fantasy, Mystery",
"director":"David Yates",
"plot":"Harry, Ron, and Hermione search for Voldemort's remaining Horcruxes in their effort to destroy the Dark Lord as the final battle rages on at Hogwarts.",
"poster":"https://m.media-amazon.com/images/M/MV5BMjIyZGU4YzUtNDkzYi00ZDRhLTljYzctYTMxMDQ4M2E0Y2YxXkEyXkFqcGdeQXVyNTIzOTk5ODM@._V1_SX300.jpg",
"website":"http://www.HarryPotter.com/",
"createdAt":"2019-08-02T17:18:45.000Z",
"updatedAt":"2019-08-02T17:18:45.000Z"
}
}
]