A simple RESTful API built with Node.js and Express for managing movies. The data is stored in a JSON file and includes CRUD operations to create, read, update, and delete movie records.
- Name: Zhiyuan Wu.
- Email: zwu9487@conestogac.on.ca.
- Student Number: 8849487.
- Create a new movie with attributes like
title
,genre
, andreleaseYear
. - Read all movies or fetch a specific movie by ID.
- Update existing movie details using their unique ID.
- Delete movies by ID.
- Data persistence using a JSON file.
Follow these steps to set up the project locally:
-
Clone the Repository
Clone the repository to your local machine:git clone <repository_url> cd <project_directory>
-
Install Dependencies
Install the required Node.js dependencies:npm install
-
Run the Application
Start the server locally:node index.js
The server will start at
http://localhost:3000
.
- POST
http://localhost:3000/movies
- Request Body Example:
{ "title": "Inception", "genre": "Sci-Fi", "releaseYear": 2010 }
- Response Example:
{ "id": 123456789, "title": "Inception", "genre": "Sci-Fi", "releaseYear": 2010 }
- GET
http://localhost:3000/movies
- Response Example:
[ { "id": 123456789, "title": "Inception", "genre": "Sci-Fi", "releaseYear": 2010 }, { "id": 987654321, "title": "The Matrix", "genre": "Action", "releaseYear": 1999 } ]
- GET
http://localhost:3000/movies/:id
- Replace
:id
with the actual movie ID. - Example:
http://localhost:3000/movies/123456789
- Replace
- Response Example (if ID exists):
{ "id": 123456789, "title": "Inception", "genre": "Sci-Fi", "releaseYear": 2010 }
- Response Example (if ID does not exist):
{ "message": "Movie not found" }
- PUT
http://localhost:3000/movies/:id
- Replace
:id
with the actual movie ID. - Example:
http://localhost:3000/movies/123456789
- Replace
- Request Body Example:
{ "genre": "Action" }
- Response Example:
{ "id": 123456789, "title": "Inception", "genre": "Action", "releaseYear": 2010 }
- DELETE
http://localhost:3000/movies/:id
- Replace
:id
with the actual movie ID. - Example:
http://localhost:3000/movies/123456789
- Replace
- Response Example (if ID exists):
{ "message": "Movie deleted successfully", "deletedMovie": { "id": 123456789, "title": "Inception", "genre": "Sci-Fi", "releaseYear": 2010 } }
- Response Example (if ID does not exist):
{ "message": "Movie not found" }
Here are some example cURL commands for testing the endpoints:
-
Create a Movie:
curl -X POST http://localhost:3000/movies -H "Content-Type: application/json" -d '{"title": "The Dark Knight", "genre": "Action", "releaseYear": 2008}'
-
Get All Movies:
curl -X GET http://localhost:3000/movies
-
Get a Movie by ID:
curl -X GET http://localhost:3000/movies/123456789
-
Update a Movie:
curl -X PUT http://localhost:3000/movies/123456789 -H "Content-Type: application/json" -d '{"genre": "Thriller"}'
-
Delete a Movie:
curl -X DELETE http://localhost:3000/movies/123456789