GET /v2/books/{bookId} endpoint to return ETag and Cache-Control headers you need to cache book details and reduce unnecessary API calls.
Prerequisites
Before you begin, ensure you meet the following prerequisites:- Familiarity with BookHub Publisher API v2.
- A valid JWT for authentication.
- A
bookIdfor the book whose details you want to cache. In Python examples, thebookIdis assigned to abook_idvariable following Python naming conventions. When you create a book (POST /v2/books), it create abookIdand displays it in the201 Createdresponse. If you don’t know thebookId, you can find it using the (GET /v2/books). - Access to your codebase that integrates with the BookHub Publisher API v2.
Step 1: Make an initial request
Send aGET request to retrieve book details. The response includes an ETag header with a unique identifier for the current version of the resource, and a Cache-Control header indicating how long the response can be cached.
The examples in this document use
123e4567-e89b-41d4-a716-426614174000) as the bookId in the cURL examples and book_id in the Python examples.Response headers
Step 2: Use ETag for conditional requests
For subsequent requests, include the If-None-Match header with the ETag value from Step 1. If the book details haven’t changed, the server returns 304 Not Modified. 304 means use your stored data. If they have changed, the server returns a 200 OK with updated details.
Step 3: Test your implementation
Send an initial request and store theETag; then send a second conditional request with the ETag from the initial request, including the If-None-Match header. Confirm the second request returns 304 Not Modified if the book details haven’t changed.
Initial request
Conditional request
304 Not Modified if the book details haven’t changed.
Response
A304 Not Modified response returns no headers beyond the standard HTTP response headers — no body is returned. The Cache-Control: max-age=3600, must-revalidate header in the initial response means the cached data is valid for 3600 seconds (one hour). After expiry, the cache must revalidate with the server before serving the cached response.
A 200 OK response returns updated book details:
Error handling
Next steps
Explore related topics:How-to guides
- Handle pagination — Manage large result sets when retrieving all books.
- Rank books by hitCount to find top performers — Use the
hitCountfield to rank books by buyer interest and flag your top performers.
Reference
- Get a specific book — Explore all available API endpoints and their parameters for BookHub Publisher API v2.
- Data models — Explore schema definitions for BaseBook, BookWithAnalytics, Pagination, and Error response objects in the BookHub Publisher API v2.