1. Organise Your Restaurants/Reviews API
Apply the code organisation patterns from this lesson to your restaurants/reviews API from Module 2.
- Move your Restaurant and Review interfaces to
src/interfaces.tswith exports. - Create
routes/restaurants.tsfor all restaurant endpoints (including/restaurants/:id/reviews). - Create
routes/reviews.tsforPOST /reviews. - Update
index.tsto useapp.use("/restaurants", restaurantRoutes)andapp.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
- Install
swagger-ui-expressandswagger-jsdocpackages. - Set up Swagger configuration in your
index.tsand create an/api-docsendpoint. - Add documentation comments to your restaurant and review routes using
@swaggertags. - Test your interactive API documentation at
http://localhost:3000/api-docs.