There is a website with PDF books. To get a PDF, three parameters are needed: author, year, title. Users remember either the title or the author. How would you organize the search page and what API would you use to retrieve the PDF?
sobes.tech AI
Answer from AI
For the search page, I would implement two input fields: one for the author and another for the book title. The user can fill in either or both of them. The year does not need to be explicitly requested, as it serves as an additional filter and can be selected from the results.
The search will work as follows:
- If a title is entered, search by title.
- If an author is entered, search by author.
- If both parameters are entered, search by both.
The result will be a list of books with brief information (author, title, year), from which the user can select the desired book.
API to obtain the PDF:
GET /api/books/pdf?author={author}&year={year}&title={title}
Parameters:
- author — string, optional
- year — number, required (can be obtained from the selected book)
- title — string, required
If the user has selected a book from the list, the frontend knows all three parameters and can request the PDF directly. If the user enters parameters manually, the API should validate the presence of all three parameters.
This approach ensures ease of search and accuracy when obtaining the PDF.