1. Organise Your Restaurants/Reviews API

Apply the code organisation patterns from this lesson to your restaurants/reviews API from Module 2.

  1. Move your Restaurant and Review interfaces to src/interfaces.ts with exports.
  2. Create routes/restaurants.ts for all restaurant endpoints (including /restaurants/:id/reviews).
  3. Create routes/reviews.ts for POST /reviews.
  4. Update index.ts to use app.use("/restaurants", restaurantRoutes) and app.use("/reviews", reviewRoutes).

2. Extract Validation Middleware

Extract repeated validation logic from your routes into reusable middleware functions in middleware/validation.ts. Apply the middleware to your routes and remove inline validation code.

3. Add API Documentation

  1. Install swagger-ui-express and swagger-jsdoc packages.
  2. Set up Swagger configuration in your index.ts and create an /api-docs endpoint.
  3. Add documentation comments to your restaurant and review routes using @swagger tags.
  4. Test your interactive API documentation at http://localhost:3000/api-docs.
Tags: