library-rest
Return a borrowed book.
POST
/loans/{id}/returnCloses the loan with the given id, stamping returnedAt with the current time, and flips the book's status back to available. Takes no request body.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| id | path | string | yes | The loan's unique identifier. |
Responses
200 The loan was closed and the book is now available again.
application/json
| Field | Type | Required | Description |
|---|---|---|---|
| data | object | yes | A single borrow/return transaction linking a Book to a User. |
| bookId | string | yes | The id of the borrowed Book. |
| borrowedAt | string (date-time) | yes | When the loan started. |
| dueAt | string (date-time) | yes | When the book is expected back. |
| id | string | yes | Unique identifier assigned by the server, prefixed with ln_. |
| overdue | boolean | yes | Computed at response time: true if the loan is still open and past its dueAt. Never stored, so it never goes stale. |
| returnedAt | string (date-time) | When the book was actually returned, or null while the loan is still open. | |
| userId | string | yes | The id of the User who borrowed the book. |
| 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 |
|---|---|---|
| 401 | The request is missing a valid Authorization: Bearer <token> header. | |
| 404 | No resource exists with the given id. | |
| 409 | The loan has already been closed. | |
| 500 | An unexpected error occurred. The response never leaks internal error details. |
Response example
{
"data": {
"bookId": "bookId_739",
"borrowedAt": "borrowedAt_703",
"dueAt": "dueAt_979",
"id": "id_635",
"overdue": true,
"returnedAt": "returnedAt_965",
"userId": "userId_924"
},
"meta": {
"requestId": "requestId_761",
"total": 324
}
}