This repository contains your starter code for the Restaurant API assignment focusing on middleware implementation and API documentation.
- Clone this repository to your local machine
- Navigate to the project directory
- Install dependencies:
npm install
You will build a complete restaurant menu management API that demonstrates:
- Custom middleware functions for request logging and input validation
- Professional API documentation using Postman collections
- Proper HTTP status codes and error handling
- Secure API endpoints with input validation and data sanitization
Install the following package for validation:
npm install express-validatorYour API will manage menu items with this structure:
{
id: 1,
name: "Classic Burger",
description: "Beef patty with lettuce, tomato, and cheese on a sesame seed bun",
price: 12.99,
category: "entree",
ingredients: ["beef", "lettuce", "tomato", "cheese", "bun"],
available: true
}GET /api/menu- Retrieve all menu itemsGET /api/menu/:id- Retrieve a specific menu item by IDPOST /api/menu- Add a new menu itemPUT /api/menu/:id- Update an existing menu itemDELETE /api/menu/:id- Remove a menu item
Your API must implement two custom middleware functions:
- Log HTTP method, URL, and timestamp for all requests
- Log request body for POST and PUT requests
- Apply to all routes
- Validate all required fields using express-validator
- Apply to POST and PUT endpoints
- Return appropriate error messages for validation failures
- Name: Required string, minimum 3 characters
- Description: Required string, minimum 10 characters
- Price: Required number, greater than 0
- Category: Required string, must be one of: "appetizer", "entree", "dessert", "beverage"
- Ingredients: Required array with at least 1 ingredient
- Available: Boolean (defaults to true)
Your API must return appropriate status codes:
- 200 for successful GET, PUT, DELETE requests
- 201 for successful POST requests
- 400 for validation errors
- 404 for not found errors
Create comprehensive API documentation using Postman:
- Create a collection with all API endpoints
- Add clear descriptions for each endpoint
- Include example request bodies for POST/PUT
- Save response examples for both success and error cases
- Publish documentation as a public website
Use your Postman collection to test:
- All CRUD operations work correctly
- Middleware executes in proper order
- Validation middleware rejects invalid data
- Logging middleware captures all requests
- All endpoints return correct status codes
Your final submission should include:
- Complete Express.js API with all CRUD endpoints
- Two custom middleware functions (logging and validation)
- Public URL to your Postman API documentation
- Clean, organized code with meaningful variable names
server.js
package.json
README.md
Start your development server:
npm startYour API will be available at http://localhost:3000