library-rest

Partially update a book.

PATCH/books/{id}

Applies only the fields present in the request body; omitted fields are left unchanged. The book's status cannot be changed here — it only changes via POST /loans (borrow) and POST /loans/{id}/return, so it always reflects a real open loan.

Parameters

NameInTypeRequiredDescription
idpathstringyesThe book's unique identifier.

Request body

application/json

FieldTypeRequiredDescription
authorIdstringThe id of a different existing Author to reassign this book to.
isbnstringThe book's new ISBN. Must be unique across the catalog.
publishedYearintegerThe book's new published year. Must be between 1450 and next year.
titlestringThe book's new display title, 1–200 characters.

Responses

200 The updated book.

application/json

FieldTypeRequiredDescription
dataobjectyesA single library title.
authorIdstringyesThe id of the Author who wrote this book.
createdAtstring (date-time)yesWhen the book record was created.
idstringyesUnique identifier assigned by the server, prefixed with bk_.
isbnstringyesThe book's ISBN. Must be unique across the catalog.
publishedYearintegeryesThe year the book was first published. Must be between 1450 and next year.
statusstringyesA book's availability. borrowed means it is out on an open loan. Allowed values: available, borrowed
titlestringyesThe book's display title, 1–200 characters.
updatedAtstring (date-time)yesWhen the book record was last modified.
metaobjectyesResponse metadata attached to every successful response.
requestIdstringyesCorrelation id for this request, echoed from the X-Request-Id request header or generated if absent. Useful for tracing a request across logs.
totalintegerTotal number of matches before pagination was applied. Present only on paginated list responses (currently GET /books).

Errors

CodeMessageDescription
400The request body is not valid JSON.
401The request is missing a valid Authorization: Bearer <token> header.
404The book does not exist, or the new authorId does not reference an existing author.
409The new isbn is already used by another book.
415The request has a body but its Content-Type is not application/json.
422A supplied field failed validation (e.g. a blank title, or publishedYear out of range).
500An unexpected error occurred. The response never leaks internal error details.

Request example

{
  "authorId": "authorId_868",
  "isbn": "isbn_184",
  "publishedYear": 637,
  "title": "title_134"
}

Response example

{
  "data": {
    "authorId": "authorId_163",
    "createdAt": "createdAt_114",
    "id": "id_545",
    "isbn": "isbn_884",
    "publishedYear": 141,
    "status": "available",
    "title": "title_605",
    "updatedAt": "updatedAt_134"
  },
  "meta": {
    "requestId": "requestId_523",
    "total": 351
  }
}