This is a simple Express.js REST API tutorial project that demonstrates how to create a basic movie management API with CRUD operations.
- Node.js (v14 or higher)
- npm (Node Package Manager)
- Thunder Client VS Code extension
- Clone the repository:
git clone https://github.com/oliverTwist2/express-rest-tutorial.git
cd express-rest-tutorial- Install dependencies:
npm install- Start the server:
node server.jsThe server will start running on http://localhost:8000
- GET
/movies - Returns a list of all movies
- GET
/movies/:id - Returns a specific movie by its ID
- POST
/movies - Creates a new movie
- Required fields in request body:
{ "title": "Movie Title", "genre": "Movie Genre", "year": 2024 }
- PUT
/movies/:id - Updates an existing movie
- Required fields in request body:
{ "title": "Updated Title", "genre": "Updated Genre", "year": 2024 }
- DELETE
/movies/:id - Deletes a movie by its ID
- Open VS Code and install the Thunder Client extension
- Click on the Thunder Client icon in the sidebar
- Create a new request collection for the movie API
- Test each endpoint using the following examples:
- Method: POST
- URL:
http://localhost:8000/movies - Body (JSON):
{ "title": "The Matrix", "genre": "Sci-Fi", "year": 1999 }
- Method: GET
- URL:
http://localhost:8000/movies
- Method: GET
- URL:
http://localhost:8000/movies/1
- Method: PUT
- URL:
http://localhost:8000/movies/1 - Body (JSON):
{ "title": "The Matrix Reloaded", "genre": "Sci-Fi", "year": 2003 }
- Method: DELETE
- URL:
http://localhost:8000/movies/1
The API includes basic error handling:
- 400: Bad Request (missing required fields)
- 404: Not Found (movie not found)
- 500: Internal Server Error
This is a demonstration project using in-memory storage. In a production environment, you would want to:
- Use a proper database (MongoDB, PostgreSQL, etc.)
- Implement proper authentication and authorization
- Use environment variables for configuration
- Implement proper error handling
- Add logging
Ikegah Oliver A.