Sobes.tech
Middle

REST API task: search for a book in an electronic library by partial data (author, title, year unknown), with pagination for a large number of results.

sobes.tech AI

Answer from AI

For the task of searching for a book in an electronic library by partial data (author, title, year unknown) with pagination, the REST API can be designed as follows:

  1. Request parameters:

    • author (optional) — part or full name of the author
    • title (optional) — part or full title of the book
    • year (optional) — year of publication
    • page — page number
    • pageSize — number of results per page
  2. Request processing:

    • The server constructs a database query with filters based on the provided parameters. If a parameter is not provided, the filter is not applied.
    • Partial data search is implemented using LIKE operators or full-text search.
  3. Pagination:

    • LIMIT and OFFSET (or cursors) are used to fetch the required number of records.
    • The response returns a list of books, as well as metadata: current page, total number of pages, or total number of results.
  4. Example request:

GET /api/books?author=Толстой&title=война&page=2&pageSize=10
  1. Example response:
{
  "page": 2,
  "pageSize": 10,
  "totalResults": 57,
  "books": [
    {"id": "123", "title": "Война и мир", "author": "Лев Толстой", "year": 1869},
    ...
  ]
}

This approach provides flexible search by incomplete data and convenient navigation through the results.

REST API task: search for a book in an electronic… - sobes.tech