Request

interface Request(source)

Information passed into an API endpoint from the client.

The request information will be passed in via an ApiContext. Developers implementing an API endpoint can read request values with code like the following:

@Api
fun echo(ctx: ApiContext) {
  val msg = ctx.req.params["msg"]
  if (msg != null) {
    ctx.res.setBodyText("Received message: $msg")
  }
  else {
    ctx.res.status = 400
    ctx.res.setBodyText("Missing: required parameter 'msg'")
  }
}

See also

Inheritors

Types

Link copied to clipboard

Top-level container class for views about a connection for some request.

Properties

Link copied to clipboard
abstract val body: ByteArray?

An (optional) payload sent with the request. Will only potentially be set with appropriate methods that are allowed to send data, i.e. HttpMethod.POST, HttpMethod.PUT, and HttpMethod.PATCH

Link copied to clipboard

Information about the connection that carried the request.

Link copied to clipboard
abstract val contentType: String?

The content type of the body, if set and sent.

Link copied to clipboard
abstract val cookies: Map<String, String>

Any cookies sent with the request. Note the value of the cookies will be in a raw format, so you may need to decode them yourself.

Link copied to clipboard
abstract val headers: Map<String, List<String>>

All headers sent with the request.

Link copied to clipboard
abstract val method: HttpMethod

The type of http method this call was sent with.

Link copied to clipboard
abstract val params: Map<String, String>

A list of key/value pairs extracted either from the user's query string or from any dynamic path parts.

Link copied to clipboard
abstract val queryParams: Map<String, String>

Like params but only for the query string, just in case a user needs to disambiguate between a dynamic path part and a query parameter with the same name.

Functions

Link copied to clipboard

Convenience method to pull body text out from a request.