library-rpc

Borrow a book.

RPCloans.borrow

Creates 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/rpc

Parameters

NameInTypeRequiredDescription
bookIdparamsstringyesThe id of the book to borrow. Must currently be available.
userIdparamsstringyesThe id of the user borrowing the book.

Responses

result The loan that was created; the book is now borrowed.

application/json

FieldTypeRequiredDescription
bookIdstringyesThe id of the borrowed Book.
borrowedAtstring (date-time)yesWhen the loan started.
dueAtstring (date-time)yesWhen the book is expected back.
idstringyesUnique identifier assigned by the server, prefixed with ln_.
overduebooleanyesComputed at response time: true if the loan is still open and past its dueAt. Never stored, so it never goes stale.
returnedAtstring (date-time)When the book was actually returned, or null while the loan is still open.
userIdstringyesThe id of the User who borrowed the book.

Errors

CodeMessageDescription
-32602Invalid params
-32004Not found
-32002Book 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"
  }
}