Senior
Design a REST API service for a book catalog with filtering by author and title. What method would you choose, and what parameters?
sobes.tech AI
Answer from AI
For the REST API of the book catalog service with filtering by author and title, I would choose the GET method, as the request is intended to retrieve data without changing state.
Resource path:
GET /books
Filtering parameters are passed via query parameters:
author— the author's name or part of the nametitle— the book's title or part of the title
Example request:
GET /books?author=Толстой&title=Война
Response — a list of books matching the filters, in JSON format.
Example response:
[
{
"id": "123",
"title": "Война и мир",
"author": "Лев Толстой",
"year": 1869
}
]
This approach aligns with REST principles, allows convenient data filtering, and caching of GET requests.