Design the REST API endpoints for a simple blog with posts and comments. What URLs, methods and status codes would you use?
What the interviewer wants to hear
- Use nouns for resources and HTTP methods for actions
- Nested routes for comments under a post
- Correct status codes such as 200, 201, 204, 400, 401, 404
- Pagination and filtering through query parameters
- Validation and consistent error format
Model answer
I would model posts and comments as resources. GET /api/posts lists posts with pagination like ?limit=20&cursor=abc, and GET /api/posts/:id returns one post. POST /api/posts creates a post and returns 201 with the new object. PATCH /api/posts/:id updates some fields and DELETE /api/posts/:id returns 204. For comments, GET /api/posts/:id/comments and POST /api/posts/:id/comments, and DELETE /api/comments/:id for a single comment. I would return 400 for invalid input with a clear JSON error body, 401 when the user is not logged in, 403 when they are not allowed, and 404 when the item does not exist. I would validate input on the server with a schema library like Zod, keep the response shape consistent, and only allow the author or an admin to edit or delete a post.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Full Stack Developer questions
- What happens, step by step, when a user types your app URL into the browser and presses Enter?
- What is the difference between authentication and authorization? Give an example from a web app.
- You are starting a new e-commerce app. Would you choose a SQL or a NoSQL database, and why?
- Explain client-side rendering, server-side rendering and static site generation. When would you use each?
- In a web app with a React frontend and an API, where should input validation happen, and why?
- A page loads data from your API. How do you handle loading, empty and error states so users are never left confused?
- How do you manage configuration and secrets across development, staging and production for a full-stack app?
- How would you explain a database index to a junior developer, and how do you decide which columns to index?
- Describe the Git and code review workflow you follow when building a feature on a team.