STEPS
-
git clone https://github.com/huudy/movies-rest-api.git
-
cd movies-rest-api
-
npm i
-
CREATE A CONFIG FOLDER WITH THREE FILES :
-
dev.env:
PORT=3000
MONGODB_URI=mongodb://127.0.0.1:27017/movie-rest
OMDB_API_KEY=*x*x*x*x
-
test.env:
PORT=3000
MONGODB_URI=mongodb://127.0.0.1:27017/movie-rest-test
OMDB_API_KEY=*x*x*x*x
-
dc.env:
PORT=3000
MONGODB_URI=mongodb://mongo:27017/movie-rest-test
OMDB_API_KEY=*x*x*x*x
You can get the OMDB_API_KEY from here => https://www.omdbapi.com/
-
-
RUN APP:
npm run dev
(make sure you have mongo db installed locally that is up and running otherwise you will get a connection error ) -
RUN TESTS:
npm run test
-
RUN DOCKER:
docker-compose up --build
(make sure you have docker and docker-compose installed if not please follow the link https://docs.docker.com/compose/install/ )
-
URL
/movies
/movies/:id
/comments
/comments/:id -
Method:
GET
|POST
|DELETE
-
Data Params
POST
/movies{ title: 'your_title'}
POST
/comments{ author: 'author_name', text:'comment_text'}
-
Success Response:
POST
/movies
- Code: 201
Content:{"Title":"Batman","Plot":"The Dark Knight of Gotham City begins his war on crime with his first major enemy being the clownishly homicidal Joker.","Message":"Movie Batman was successfully saved to the DB"}
POST
/comments
- Code: 201
Content:{"message": "Comment for author: Adam was successfully saved!"}
-
Error Response:
- Code: 409 CONFLICT
Content:{"message":"Movie MOVIE_NAME already exists!"}
OR
- Code: 500 INTERNAL ERROR
Content:{ error : "error" }
- Code: 409 CONFLICT
-
Sample Call:
curl --header "Content-Type: application/json" -d "{\"title\":\"puss in boots\"}" http://localhost:3000/movies
curl --header "Content-Type: application/json" -d "{\"author\":\"Adam\",\"text\":\"First Comment\"}" http://localhost:3000/comments