library-rest

Get a user's profile, including their loans.

GET/users/{id}/profile

Returns the user matching the given id, together with their currently open loans (currentLoans) and their closed/returned loans (loanHistory).

Parameters

NameInTypeRequiredDescription
idpathstringyesThe user's unique identifier.

Responses

200 The requested user profile.

application/json

FieldTypeRequiredDescription
dataobjectyesA user together with their current and historical loans.
currentLoansarray of objectyesThe user's currently open loans (not yet returned).
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.
loanHistoryarray of objectyesThe user's closed (returned) loans.
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.
userobjectyesA library member who can borrow books.
emailstring (email)yesThe user's contact email address.
idstringyesUnique identifier assigned by the server, prefixed with us_.
namestringyesThe user's full name.
registeredAtstring (date-time)yesWhen the user joined the library.
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
401The request is missing a valid Authorization: Bearer <token> header.
404No resource exists with the given id.
500An unexpected error occurred. The response never leaks internal error details.

Response example

{
  "data": {
    "currentLoans": [
      {
        "bookId": "bookId_435",
        "borrowedAt": "borrowedAt_360",
        "dueAt": "dueAt_679",
        "id": "id_342",
        "overdue": true,
        "returnedAt": "returnedAt_914",
        "userId": "userId_571"
      }
    ],
    "loanHistory": [
      {
        "bookId": "bookId_288",
        "borrowedAt": "borrowedAt_864",
        "dueAt": "dueAt_818",
        "id": "id_954",
        "overdue": true,
        "returnedAt": "returnedAt_190",
        "userId": "userId_730"
      }
    ],
    "user": {
      "email": "email_885",
      "id": "id_893",
      "name": "name_538",
      "registeredAt": "registeredAt_327"
    }
  },
  "meta": {
    "requestId": "requestId_120",
    "total": 217
  }
}