library-rest
Create a new book.
POST
/booksCreates a book in available status and links it to its author. The server assigns the id, createdAt and updatedAt fields.
Request body
application/json
| Field | Type | Required | Description |
|---|---|---|---|
| authorId | string | yes | The id of an existing Author who wrote this book. |
| isbn | string | yes | The book's ISBN. Must be unique across the catalog. |
| publishedYear | integer | yes | The year the book was first published. Must be between 1450 and next year. |
| title | string | yes | The book's display title, 1–200 characters. |
Responses
201 The book was created.
application/json
| Field | Type | Required | Description |
|---|---|---|---|
| data | object | yes | A single library title. |
| authorId | string | yes | The id of the Author who wrote this book. |
| createdAt | string (date-time) | yes | When the book record was created. |
| id | string | yes | Unique identifier assigned by the server, prefixed with bk_. |
| isbn | string | yes | The book's ISBN. Must be unique across the catalog. |
| publishedYear | integer | yes | The year the book was first published. Must be between 1450 and next year. |
| status | string | yes | A book's availability. borrowed means it is out on an open loan. Allowed values: available, borrowed |
| title | string | yes | The book's display title, 1–200 characters. |
| updatedAt | string (date-time) | yes | When the book record was last modified. |
| meta | object | yes | Response metadata attached to every successful response. |
| requestId | string | yes | Correlation id for this request, echoed from the X-Request-Id request header or generated if absent. Useful for tracing a request across logs. |
| total | integer | Total number of matches before pagination was applied. Present only on paginated list responses (currently GET /books). |
Errors
| Code | Message | Description |
|---|---|---|
| 400 | The request body is not valid JSON. | |
| 401 | The request is missing a valid Authorization: Bearer <token> header. | |
| 404 | authorId does not reference an existing author. | |
| 409 | isbn is already used by another book. | |
| 415 | The request has a body but its Content-Type is not application/json. | |
| 422 | A required field is missing/blank, or publishedYear is out of range. | |
| 500 | An unexpected error occurred. The response never leaks internal error details. |
Request example
{
"authorId": "authorId_101",
"isbn": "isbn_556",
"publishedYear": 851,
"title": "title_954"
}Response example
{
"data": {
"authorId": "authorId_85",
"createdAt": "createdAt_950",
"id": "id_573",
"isbn": "isbn_232",
"publishedYear": 407,
"status": "available",
"title": "title_944",
"updatedAt": "updatedAt_124"
},
"meta": {
"requestId": "requestId_704",
"total": 830
}
}