Script Valley
Express.js: APIs and Middleware
Building RESTful APIs/Assessment

Practice & Assessment

Test your understanding of Building RESTful APIs

Multiple Choice Questions

5
1

Which of the following URLs follows REST naming conventions?

2

Where must the global error handler middleware be registered in an Express app?

3

What happens in Express 4 when an async route handler throws an error without try/catch?

4

What should the `meta` field in a paginated response include at minimum?

5

What is the purpose of `err.isOperational = true` in a custom AppError class?

Coding Challenges

1
1

Products API with Pagination and Error Handling

Build a /products REST API endpoint. GET /products should support ?page, ?limit (max 20), ?sort (by price or name), and ?category filtering. Include a meta object in the response with page, limit, total, and totalPages. GET /products/:id should return 404 with { success: false, error: { message, code } } if not found. Wrap all handlers with an asyncHandler utility. Use an in-memory array of at least 30 products. Inputs: query params page/limit/sort/category. Outputs: { success, data, meta } envelope. Time estimate: 25-30 minutes.

Medium

Mini Project

1

Task Manager REST API

Build a complete Task Manager REST API with consistent response envelopes. Resources: tasks (id, title, description, status: todo/in-progress/done, priority: low/medium/high, createdAt). Endpoints: GET /api/tasks (with ?status, ?priority filters and pagination), POST /api/tasks (validate title required), GET /api/tasks/:id, PUT /api/tasks/:id, DELETE /api/tasks/:id. Implement: custom AppError class, global error handler as last middleware, asyncHandler wrapper on all handlers, consistent { success, data, meta } envelope from a response helper. All errors use { success: false, error: { message, code } } format.

Medium
Practice & Assessment โ€” Building RESTful APIs โ€” Express.js: APIs and Middleware โ€” Script Valley โ€” Script Valley