RiserBob logoRiserBobv1.0.0
HomeDocsCLIRelease notes

Getting started

  • Introduction
  • Installation
  • Quick start
  • Project structure

Core concepts

  • Routing
  • Request
  • Responses
  • Error handling

Middleware

  • Middleware
  • Authentication
  • Logger and CORS

Data

  • Validation

Structure and tooling

  • Modules
  • CLI

Examples

  • Build a project
  • Mongoose
  • Drizzle ORM
  • Sequelize
  • JWT and cookies
  • File uploads

Packages

  • Cookies

Resources

  • Troubleshooting
  • Release notes
  • License
  • Security
  • Contributing
Core concepts

Request

Everything the spongReq object gives you: params, query, headers and the request body.

Every handler and middleware receives spongReq. It wraps the standard Fetch Request and adds what you need most.

PropertyTypeDescription
requestRequestThe original Fetch request.
methodstringHTTP method, for example GET.
urlURLThe full parsed URL.
pathstringThe pathname, without the query string.
paramsRecord<string, string>Route parameters, already decoded.
queryURLSearchParamsThe query string.
headersHeadersRequest headers.
user{ id: string; [key: string]: unknown }Set by AuthMiddleware after a valid token. It holds whatever your verifier returned.
auth{ token: string }Set together with user.

Reading the body

MethodReturnsNotes
json<T>()Promise<T>The Content-Type must be application/json or a +json type.
formData()Promise<FormData>Needs a Content-Type header. Uploaded files arrive as File objects.
text()Promise<string>The raw body as text.
TypeScript
bob.spongPost('/users', async (spongReq, spongRes) => {  const body = await spongReq.json<{ name: string }>()   return spongRes.json({ created: body.name })})

What can go wrong

Body problems are reported as HttpError, so the client always gets a clear JSON answer.

SituationResponse
json() on a request that is not JSON415 Unsupported Media Type
The body is not valid JSON400 Invalid JSON body
formData() without a Content-Type400 Missing Content-Type
The form data cannot be parsed400 Invalid form data
The body is larger than 10 MiB413 Content Too Large
An invalid Content-Length header400 Invalid Content-Length
The size limit is checked twice: against the declared Content-Length before any work is done, and again while the body is being read, so a client cannot bypass it by lying about the size.
The limit applies to the whole request. If you accept uploads, also check each file with file.size and file.type. See File uploads.
PreviousRoutingNextResponses

On this page

  • Reading the body
  • What can go wrong