Types
ContentBody = object contentType*: ContentTypeData data*: seq[byte]
- Source Edit
ResponseContentBody = object contentType*: string data*: seq[byte]
- Source Edit
RestApiError = object status*: HttpCode message*: string contentType*: string
- Source Edit
RestApiResponse = object status*: HttpCode headers*: HttpTable case kind*: RestApiResponseKind of RestApiResponseKind.Empty: nil of RestApiResponseKind.Status: nil of RestApiResponseKind.Content: content*: ResponseContentBody of RestApiResponseKind.Error: errobj*: RestApiError of RestApiResponseKind.Redirect: location*: string preserveQuery*: bool
- Source Edit
RestApiResponseKind {.pure.} = enum Empty, Error, Redirect, Content, Status
- Source Edit
RestBadRequestError = object of RestError
- Source Edit
RestCommunicationError = object of RestError exc*: ref CatchableError
- Source Edit
RestDecodingError = object of RestError
- Source Edit
RestDefect = object of Defect
- Source Edit
RestDnsResolveError = object of RestError hostname*: string
- Source Edit
RestEncodingError = object of RestError field*: cstring
- Source Edit
RestKeyValueTuple = tuple[key: string, value: string]
- Source Edit
RestRedirectionError = object of RestError
- Source Edit
RestResponseError = object of RestError status*: int contentType*: string message*: string
- Source Edit
RestResult[T] = Result[T, cstring]
- Source Edit
RestServerMetricsType {.pure.} = enum Response, ## Enable metric which measures time used to prepare response Status ## Enable metric which counts response's HTTP status.
- Source Edit
Consts
RestServerMetrics = {RestServerMetricsType.Response, RestServerMetricsType.Status}
- Source Edit
Procs
proc error(t: typedesc[RestApiResponse]; status: HttpCode = Http200; msg: string = ""; contentType: string = "text/html"): RestApiResponse {. ...raises: [].}
- Source Edit
proc error(t: typedesc[RestApiResponse]; status: HttpCode = Http200; msg: string = ""; contentType: string = "text/html"; headers: openArray[RestKeyValueTuple]): RestApiResponse {....raises: [].}
- Source Edit
proc error(t: typedesc[RestApiResponse]; status: HttpCode = Http200; msg: string = ""; contentType: string = "text/html"; headers: HttpTable): RestApiResponse {....raises: [].}
-
Create REST API error response with status status and content specified by type contentType and data data. You can also specify additional HTTP response headers using headers argument.
Please note that contentType argument's value has priority over Content-Type header's value in headers table.
Source Edit proc init(t: typedesc[ContentBody]; contentType: MediaType; data: openArray[byte]): ContentBody {....raises: [].}
- Source Edit
proc raiseRestDnsResolveError(msg: string; hostname: string) {.noinline, noreturn, ...raises: [RestDnsResolveError], raises: [], tags: [], forbids: [].}
- Source Edit
proc redirect(t: typedesc[RestApiResponse]; status: HttpCode = Http307; location: string; preserveQuery = false): RestApiResponse {. ...raises: [].}
- Source Edit
proc redirect(t: typedesc[RestApiResponse]; status: HttpCode = Http307; location: string; preserveQuery = false; headers: openArray[RestKeyValueTuple]): RestApiResponse {. ...raises: [].}
- Source Edit
proc redirect(t: typedesc[RestApiResponse]; status: HttpCode = Http307; location: string; preserveQuery = false; headers: HttpTable): RestApiResponse {. ...raises: [].}
-
Create REST API redirect response with status status and new location location.
You can preserve HTTP query string uri.query part using preserveQuery argument. When preserveQuery is true new query string will be formed as concatenation of original HTTP request query string and location query string.
You can also specify additional HTTP response headers using headers argument.
Please note that location argument's value has priority over Location header's value in headers table.
Source Edit proc response(t: typedesc[RestApiResponse]; data: ByteChar; status: HttpCode = Http200; contentType = "text/plain"): RestApiResponse {. ...raises: [].}
- Source Edit
proc response(t: typedesc[RestApiResponse]; data: ByteChar; status: HttpCode = Http200; contentType = "text/plain"; headers: HttpTable): RestApiResponse {....raises: [].}
-
Create REST API data response with status status and content specified by type contentType and data data. You can also specify additional HTTP response headers using headers argument.
Please note that contentType argument's value has priority over Content-Type header's value in headers table.
Source Edit proc response(t: typedesc[RestApiResponse]; data: ByteChar; status: HttpCode = Http200; contentType = "text/plain"; headers: openArray[RestKeyValueTuple]): RestApiResponse {. ...raises: [].}
- Source Edit
proc response(t: typedesc[RestApiResponse]; status: HttpCode = Http200): RestApiResponse {. ...raises: [].}
- Source Edit
proc response(t: typedesc[RestApiResponse]; status: HttpCode; headers: openArray[RestKeyValueTuple]): RestApiResponse {. ...raises: [].}
- Source Edit
proc response(t: typedesc[RestApiResponse]; status: HttpCode; headers: HttpTable): RestApiResponse {. ...raises: [].}
- Create REST API data response with status status and without any content. You can also specify additional HTTP response headers using headers argument. Source Edit