library-rpc
Borrow a book.
RPC
loans.borrowCreates a new loan for bookId and userId, due back 14 days from now, and flips the book's status to "borrowed". As with a real library, a book that is already out on loan cannot be borrowed again until it is returned.
Servers
•
mock: https://mock.api.selfdochub.com/rpcParameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| bookId | params | string | yes | The id of the book to borrow. Must currently be available. |
| userId | params | string | yes | The id of the user borrowing the book. |
Responses
result The loan that was created; the book is now borrowed.
application/json
| Field | Type | Required | Description |
|---|---|---|---|
| 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. |
Errors
| Code | Message | Description |
|---|---|---|
| -32602 | Invalid params | |
| -32004 | Not found | |
| -32002 | Book already borrowed |
Request example
{
"id": 1,
"jsonrpc": "2.0",
"method": "loans.borrow",
"params": {
"bookId": "bookId_497",
"userId": "userId_247"
}
}Response example
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"bookId": "bookId_273",
"borrowedAt": "borrowedAt_558",
"dueAt": "dueAt_406",
"id": "id_395",
"overdue": true,
"returnedAt": "returnedAt_87",
"userId": "userId_306"
}
}