Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @ovotech/laminar

Index

Classes Other

Classes http

Interfaces HttpResponse

Interfaces Other

Interfaces Response

Interfaces application

Interfaces http

Interfaces logger

Type aliases Other

Type aliases application

Type aliases http

Variables Other

Variables http

Functions HttpResponse

Functions Other

Functions application

Functions http

Functions logger

Other Type aliases

AbstractMiddleware<TRequest, TResponse, TProvide, TRequire>: <TInherit>(next: (ctx: TProvide & TRequire & TInherit) => Promise<TResponse>) => (ctx: TRequire & TInherit) => Promise<TResponse>

Type parameters

Type declaration

    • <TInherit>(next: (ctx: TProvide & TRequire & TInherit) => Promise<TResponse>): (ctx: TRequire & TInherit) => Promise<TResponse>
    • A type to help with creating specific middlewares. Allows you to say create a middleware for a function that takes those specific arguments and returns a specific type. This is used throughout laminar to define type like and WorkerMiddleware

      For example this will create a middlware type for function that would always accept MyRequest type.

      interface MyRequest {
      text: string;
      }
      type MyMiddleware<TProvide extends Empty = Empty, TRequire extends Empty = Empty> = AbstractMiddleware<MyRequest, void, TProvide, Trequire>;

      Type parameters

      • TInherit: TRequest

      Parameters

      • next: (ctx: TProvide & TRequire & TInherit) => Promise<TResponse>
          • (ctx: TProvide & TRequire & TInherit): Promise<TResponse>
          • Parameters

            • ctx: TProvide & TRequire & TInherit

            Returns Promise<TResponse>

      Returns (ctx: TRequire & TInherit) => Promise<TResponse>

        • (ctx: TRequire & TInherit): Promise<TResponse>
        • Parameters

          • ctx: TRequire & TInherit

          Returns Promise<TResponse>

Empty: {}

Used throughout the project to express "empty object"

Type declaration

    HttpErrorHandler: (ctx: HttpContext & RequestError) => Promise<HttpResponse>

    Type declaration

    HttpListener<TRequest>: (ctx: HttpContext & TRequest) => Promise<HttpResponse>

    Type parameters

    • TRequest: Empty = Empty

      pass the request properties that the app requires. Usually added by the middlewares

    Type declaration

    HttpMiddleware<TProvide, TRequire>: AbstractMiddleware<HttpContext, HttpResponse, TProvide, TRequire>

    An middleware that uses HttpContext and modifies it to be used by the app or the downstream middlewares

    You can compose middlewares in order to build a larger app. Each middlewares would process the request parameters and add new ones, that would be available to downstream components.

    const app: App = ...;

    const middleware1: Middleware = ...;
    const middleware2: Middleware = ...;

    const appWithMiddlewares = middleware1(middleware2(app));
    typeparam TInherit

    A helper type to allow Typescript to correctly infer the types of all the previous / next middleware in the flow

    returns

    A function to compose with other middlewares over an app

    Type parameters

    HttpResponseBody: Readable | Buffer | string

    A response that can be rendered by Laminar direcrectly, and would not need to be processed. All response bodies should be converted to tbis

    IncommingMessageResolver: (incommingMessage: IncomingMessage) => Promise<HttpResponse>

    Type declaration

      • Parameters

        • incommingMessage: IncomingMessage

        Returns Promise<HttpResponse>

    Json<T>: T extends Date ? string : T extends string | number | boolean | null | undefined ? T : T extends Buffer ? { data: number[]; type: "Buffer" } : { [ K in keyof T]: T[K] extends infer U[] ? Json<U>[] : Json<T[K]> }

    Deeply convert one typescript type to another, following nested objects and arrays

    interface MyType {
    date: Date;
    }

    type JsonMyTpe = Json<MyType>

    // JsonMyTpe['date'] will be string

    Type parameters

    • T

    Middleware<TProvide, TRequire>: <TInherit, TResponse>(next: (ctx: TProvide & TRequire & TInherit) => Promise<TResponse>) => (ctx: TRequire & TInherit) => Promise<TResponse>

    Type parameters

    Type declaration

      • <TInherit, TResponse>(next: (ctx: TProvide & TRequire & TInherit) => Promise<TResponse>): (ctx: TRequire & TInherit) => Promise<TResponse>
      • An middleware that uses HttpContext and modifies it to be used by the app or the downstream middlewares

        You can compose middlewares in order to build a larger app. Each middlewares would process the request parameters and add new ones, that would be available to downstream components.

        const app: App = ...;

        const middleware1: Middleware = ...;
        const middleware2: Middleware = ...;

        const appWithMiddlewares = middleware1(middleware2(app));

        Type parameters

        • TInherit

          A helper type to allow Typescript to correctly infer the types of all the previous / next middleware in the flow

        • TResponse

        Parameters

        • next: (ctx: TProvide & TRequire & TInherit) => Promise<TResponse>
            • (ctx: TProvide & TRequire & TInherit): Promise<TResponse>
            • Parameters

              • ctx: TProvide & TRequire & TInherit

              Returns Promise<TResponse>

        Returns (ctx: TRequire & TInherit) => Promise<TResponse>

        A function to compose with other middlewares over an app

          • (ctx: TRequire & TInherit): Promise<TResponse>
          • Parameters

            • ctx: TRequire & TInherit

            Returns Promise<TResponse>

    OapiAuthInfo: any

    The authorized user, returned by OapiSecurityResolver

    OriginChecker: (requestOrigin: string) => boolean

    Type declaration

      • (requestOrigin: string): boolean
      • Parameters

        • requestOrigin: string

        Returns boolean

    ResponseCreator<TResponseBody, TStatus, THeaders>: (body: TResponseBody, headers?: OutgoingHttpHeaders) => { body: TResponseBody; headers: THeaders; status: TStatus }

    Type parameters

    • TResponseBody

    • TStatus

    • THeaders

    Type declaration

      • (body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: THeaders; status: TStatus }
      • A HttpResponse creator helper, used for optional

        Parameters

        • body: TResponseBody
        • Optional headers: OutgoingHttpHeaders

        Returns { body: TResponseBody; headers: THeaders; status: TStatus }

        • body: TResponseBody
        • headers: THeaders
        • status: TStatus

    application Type aliases

    InitOrder: Service | InitOrder[]

    A recursive list of Service instances or arrays of Service instances.

    http Type aliases

    AppRoute<TContext>: HttpListener<TContext & RouteContext>

    Captured path parameters to the route would be passed to the path property.

    Type parameters

    • TContext: Empty = Empty

      pass the request properties that the listener requires. Usually added by the middlewares

    AppRouteOapi<TContext>: HttpListener<TContext & OapiContext & SecurityOk>

    Type parameters

    Matcher<TContext>: (ctx: TContext & HttpContext) => RouteContext | false

    Type parameters

    • TContext

      pass the request properties that the listener requires. Usually added by the middlewares

    Type declaration

    OapiSecurityResolver<TContext, TOapiAuthInfo>: (ctx: TContext & HttpContext & OapiContext & RequestSecurityResolver) => Security<TOapiAuthInfo> | Promise<Security<TOapiAuthInfo>>

    Type parameters

    Type declaration

    Security<TOapiAuthInfo>: SecurityOk<TOapiAuthInfo> | HttpError

    Type parameters

    Other Variables

    defaultBodyParsers: BodyParser[] = ...

    http Variables

    defaultResponseParsers: ResponseParser[] = ...
    defaultResponseTimeHeader: "x-response-time" = 'x-response-time'

    The default header used by responseTimeMiddleware

    formResponseParser: ResponseParser = ...
    jsonResponseParser: ResponseParser = ...
    parseDefault: BodyParser = ...

    Http body parser for anything, just concatenates the stream

    parseForm: BodyParser = ...

    Http body parser for url encoded requests (http forms)

    parseJson: BodyParser = ...

    Http body parser for json requests

    parseText: BodyParser = ...

    Http body parser for plain text requests

    HttpResponse Functions

    • badRequest<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 400 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 400

      The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 400 }

    • binary<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "application/octet-stream" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: application/octet-stream

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "application/octet-stream" } }

    • css<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "text/css" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: text/css

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "text/css" } }

    • csv<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "text/csv" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: text/csv

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "text/csv" } }

    • Return a file response. Setting the 'content-type', 'content-length', 'last-modified' headers based on the file itself. Supports content ranges as well, if you pass the incommingMessage from the request, so it can determine the range.

      'Content-Type' header is set by inspecting the file extention. If no match could be found, defaults to 'text/plain'.

      Would set the 'Last-Modified', 'Content-Type' and 'Content-Length' headers If you provide incommingMessage, would set 'Last-Modified', 'Content-Type' and 'Accept-Ranges'. Also 'Content-Range' if there was a 'Range' header in the request

      Parameters

      • filename: string

        a local path to the file.

      • __namedParameters: Partial<HttpResponse<unknown, number>> & FileOptions = {}

      Returns HttpResponse<Readable | string>

    • forbidden<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 403 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 403

      The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 403 }

    • form<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "application/x-www-form-urlencoded" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: application/x-www-form-urlencoded

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "application/x-www-form-urlencoded" } }

    • found<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 302 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 302

      Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 302 }

    • html<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "text/html" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: text/html

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "text/html" } }

    • htmlBadRequest<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 400 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and badRequest

      Content-Type: text/html Status: 400

      The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 400 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 400
    • htmlCreated<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 201 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and noContent No body is specified as this response should not have any content

      Content-Type: text/html Status: 201

      The request has been fulfilled, resulting in the creation of a new resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 201 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 201
    • htmlForbidden<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 403 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and forbidden

      Content-Type: text/html Status: 403

      The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 403 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 403
    • htmlFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 302 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and found

      Content-Type: text/html Status: 302

      Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 302 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 302
    • htmlInternalServerError<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 500 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and internalServerError

      Content-Type: text/html Status: 500

      A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 500 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 500
    • htmlMovedPermanently<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 301 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and movedPermanently

      Content-Type: text/html Status: 301

      This and all future requests should be directed to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 301 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 301
    • htmlNotFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 404 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and notFound

      Content-Type: text/html Status: 404

      The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 404 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 404
    • htmlOk<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 200 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and ok

      Content-Type: text/html Status: 200

      Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 200 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 200
    • htmlSeeOther<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 303 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and seeOther

      Content-Type: text/html Status: 303

      The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 303 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 303
    • htmlUnauthorized<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 401 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of html and unauthorized

      Content-Type: text/html Status: 401

      Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/html" } & OutgoingHttpHeaders; status: 401 }

      • body: TResponseBody
      • headers: { content-type: "text/html" } & OutgoingHttpHeaders
      • status: 401
    • internalServerError<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 500 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 500

      A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 500 }

    • json<TResponseBody, TResponse>(res: TResponse): TResponse & { body: Json<TResponseBody>; headers: { content-type: "application/json" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant. Deeply convert JS Date types to string and remove undefined values.

      Content-Type: application/json

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { body: Json<TResponseBody>; headers: { content-type: "application/json" } }

    • jsonBadRequest<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 400 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and badRequest

      Content-Type: application/json Status: 400

      The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 400 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 400
    • jsonCreated<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 201 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and noContent No body is specified as this response should not have any content

      Content-Type: application/json Status: 201

      The request has been fulfilled, resulting in the creation of a new resource

      Type parameters

      • TResponseBody

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 201 }

      • body: TResponseBody
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 201
    • jsonForbidden<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 403 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and forbidden

      Content-Type: application/json Status: 403

      The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 403 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 403
    • jsonFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 302 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and found

      Content-Type: application/json Status: 302

      Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 302 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 302
    • jsonInternalServerError<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 500 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and internalServerError

      Content-Type: application/json Status: 500

      A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 500 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 500
    • jsonMovedPermanently<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 301 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and movedPermanently

      Content-Type: application/json Status: 301

      This and all future requests should be directed to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 301 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 301
    • jsonNoContent(headers?: OutgoingHttpHeaders): { body: undefined; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 204 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and noContent No body is specified as this response should not have any content

      Content-Type: application/json Status: 204

      The server successfully processed the request, and is not returning any content.

      Parameters

      • headers: OutgoingHttpHeaders = {}

      Returns { body: undefined; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 204 }

      • body: undefined
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 204
    • jsonNotFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 404 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and notFound

      Content-Type: application/json Status: 404

      The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 404 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 404
    • jsonOk<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 200 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and ok Deeply convert JS Date types to string and remove undefined values.

      Content-Type: application/json Status: 200

      Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 200 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 200
    • jsonSeeOther<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 303 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of json and seeOther

      Content-Type: application/json Status: 303

      The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 303 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 303
    • jsonUnauthorized<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 401 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. Deeply convert JS Date types to string and remove undefined values. A combination of json and unauthorized

      Content-Type: application/json Status: 401

      Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: Json<TResponseBody>; headers: { content-type: "application/json" } & OutgoingHttpHeaders; status: 401 }

      • body: Json<TResponseBody>
      • headers: { content-type: "application/json" } & OutgoingHttpHeaders
      • status: 401
    • movedPermanently<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 301 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 301

      This and all future requests should be directed to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 301 }

    • noContent<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 204 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 204

      The server successfully processed the request, and is not returning any content.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 204 }

    • notFound<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 404 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 404

      The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 404 }

    • notModified<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 304 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 304

      Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 304 }

    • ok<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 200 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 200

      Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 200 }

    • optional<TResponseBody, TStatus, THeaders>(response: ResponseCreator<TResponseBody, TStatus, THeaders>, body: TResponseBody, headers?: OutgoingHttpHeaders): { body: Exclude<TResponseBody, undefined>; headers: THeaders; status: TStatus }
    • optional<TResponseBody, TStatus, THeaders>(response: ResponseCreator<TResponseBody, TStatus, THeaders>, body: undefined, headers?: OutgoingHttpHeaders): undefined
    • A helper to allow optional bodies to be chained with nullish coallesing For example you can combine jsonOk and jsonNotFound

      const handler = () => {
      const value: MyType | undefined = ...
      return optional(jsonOk, value) ?? jsonNotFound({ message: 'Not Found' });
      }

      Type parameters

      • TResponseBody

        Strictly type the response body, can be undefined too

      • TStatus

        Strictly type the http status value

      • THeaders

        Strictly type the http headers.

      Parameters

      • response: ResponseCreator<TResponseBody, TStatus, THeaders>
      • body: TResponseBody
      • Optional headers: OutgoingHttpHeaders

      Returns { body: Exclude<TResponseBody, undefined>; headers: THeaders; status: TStatus }

      • body: Exclude<TResponseBody, undefined>
      • headers: THeaders
      • status: TStatus
    • Type parameters

      • TResponseBody

      • TStatus

      • THeaders

      Parameters

      • response: ResponseCreator<TResponseBody, TStatus, THeaders>
      • body: undefined
      • Optional headers: OutgoingHttpHeaders

      Returns undefined

    • pdf<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "application/pdf" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: application/pdf

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "application/pdf" } }

    • Create a response object that will redirect to a given location. Sets the 'Location' header.

      Parameters

      • location: string

        URL the location to redirect to, would be set as the "Location" header

      • __namedParameters: Partial<HttpResponse<unknown, number>> = {}

      Returns HttpResponse

    • response<TResponseBody>(__namedParameters?: Partial<HttpResponse<TResponseBody, number>>): { body: undefined | TResponseBody; headers: OutgoingHttpHeaders; status: number }
    • Type parameters

      • TResponseBody

        The type of the response body

      Parameters

      • __namedParameters: Partial<HttpResponse<TResponseBody, number>> = {}

      Returns { body: undefined | TResponseBody; headers: OutgoingHttpHeaders; status: number }

      • body: undefined | TResponseBody
      • headers: OutgoingHttpHeaders
      • status: number
    • seeOther<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 303 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 303

      The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 303 }

    • setCookie<THttpResponse>(cookies: {}, res: THttpResponse): THttpResponse
    • text<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "text/plain" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: text/plain

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "text/plain" } }

    • textBadRequest<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: OutgoingHttpHeaders } & { status: 400 } & { headers: { content-type: "text/plain" } }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and badRequest

      Content-Type: text/plain Status: 400

      The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: OutgoingHttpHeaders } & { status: 400 } & { headers: { content-type: "text/plain" } }

    • textCreated<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 201 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and noContent No body is specified as this response should not have any content

      Content-Type: text/plain Status: 201

      The request has been fulfilled, resulting in the creation of a new resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 201 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 201
    • textForbidden<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 403 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and forbidden

      Content-Type: text/plain Status: 403

      The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 403 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 403
    • textFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 302 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and found

      Content-Type: text/plain Status: 302

      Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 302 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 302
    • textInternalServerError<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 500 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and internalServerError

      Content-Type: text/plain Status: 500

      A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 500 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 500
    • textMovedPermanently<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 301 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and movedPermanently

      Content-Type: text/plain Status: 301

      This and all future requests should be directed to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 301 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 301
    • textNotFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 404 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and notFound

      Content-Type: text/plain Status: 404

      The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 404 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 404
    • textOk<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 200 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and ok

      Content-Type: text/plain Status: 200

      Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 200 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 200
    • textSeeOther<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 303 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and seeOther

      Content-Type: text/plain Status: 303

      The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 303 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 303
    • textUnauthorized<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 401 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of text and unauthorized

      Content-Type: text/plain Status: 401

      Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "text/plain" } & OutgoingHttpHeaders; status: 401 }

      • body: TResponseBody
      • headers: { content-type: "text/plain" } & OutgoingHttpHeaders
      • status: 401
    • unauthorized<TResponseBody, TResponse>(res: TResponse): TResponse & { status: 401 }
    • A helper to set the status of a HttpResponse to a specific type literal constant.

      Status: 401

      Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { status: 401 }

    • xml<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "application/xml" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: application/xml

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "application/xml" } }

    • yaml<TResponseBody, TResponse>(res: TResponse): TResponse & { headers: { content-type: "application/yaml" } }
    • A helper to set the Content-Type header of a HttpResponse to a specific type literal constant.

      Content-Type: application/yaml

      Type parameters

      • TResponseBody

        Strictly type the response body

      • TResponse: Partial<HttpResponse<TResponseBody, number>>

        A generic response, allowing us to preserve the types passed from previous helpers

      Parameters

      • res: TResponse

      Returns TResponse & { headers: { content-type: "application/yaml" } }

    • yamlBadRequest<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 400 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and badRequest

      Content-Type: application/yaml Status: 400

      The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 400 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 400
    • yamlCreated<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 201 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and noContent No body is specified as this response should not have any content

      Content-Type: application/yaml Status: 201

      The request has been fulfilled, resulting in the creation of a new resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 201 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 201
    • yamlForbidden<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 403 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and forbidden

      Content-Type: application/yaml Status: 403

      The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 403 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 403
    • yamlFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 302 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and found

      Content-Type: application/yaml Status: 302

      Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 302 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 302
    • yamlInternalServerError<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 500 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and internalServerError

      Content-Type: application/yaml Status: 500

      A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 500 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 500
    • yamlMovedPermanently<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 301 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and movedPermanently

      Content-Type: application/yaml Status: 301

      This and all future requests should be directed to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 301 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 301
    • yamlNotFound<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 404 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and notFound

      Content-Type: application/yaml Status: 404

      The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 404 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 404
    • yamlOk<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 200 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and ok

      Content-Type: application/yaml Status: 200

      Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 200 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 200
    • yamlSeeOther<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 303 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and seeOther

      Content-Type: application/yaml Status: 303

      The response to the request can be found under another URI using the GET method. When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 303 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 303
    • yamlUnauthorized<TResponseBody>(body: TResponseBody, headers?: OutgoingHttpHeaders): { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 401 }
    • A helper to create a HttpResponse object with specific type literal constants for Status and Content-Type Header. A combination of yaml and unauthorized

      Content-Type: application/yaml Status: 401

      Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthorised", the user does not have valid authentication credentials for the target resource.

      Type parameters

      • TResponseBody

        Strictly type the response body

      Parameters

      • body: TResponseBody
      • headers: OutgoingHttpHeaders = {}

      Returns { body: TResponseBody; headers: { content-type: "application/yaml" } & OutgoingHttpHeaders; status: 401 }

      • body: TResponseBody
      • headers: { content-type: "application/yaml" } & OutgoingHttpHeaders
      • status: 401

    Other Functions

    • concatStream(stream: Readable): Promise<string | undefined>
    • parseBody(incommingMessage: IncomingMessage, parsers?: BodyParser[]): Promise<unknown>
    • parseCookie(cookie: string): Record<string, string>
    • Parse a cookie header.

      Parse the given cookie header string into an object The object has the various cookies as keys(names) => values

      Parameters

      • cookie: string

      Returns Record<string, string>

    • parseMultipartBuffer(boundary: Buffer, headers: string, state: State, buffer: Buffer): { headers: string; index: number; items: MultipartItem[]; state: State }
    • parseQueryObjects(searchParams: URLSearchParams): Obj
    • Convert a URLSearchParams into a nested object. Supports ',' separateros as well as a[a][b] like names to build nested objects and arrays

      Parameters

      • searchParams: URLSearchParams

      Returns Obj

    • passThroughMiddleware<TPassThroughContext>(pass: TPassThroughContext): Middleware<TPassThroughContext>
    • A generic middleware that will just pass any params into the context of the function execution.

      const myCtx = { testDate: new Date() };

      const withTestDate = passThroughMiddleware(myCtx);

      new HttpListener({
      listener: withTestDate(async ({ testDate }) => {
      console.log(testDate);
      })
      })

      Type parameters

      • TPassThroughContext: Empty

        pass through all the params of the context as is.

      Parameters

      • pass: TPassThroughContext

        pass through all the params of the context as is.

      Returns Middleware<TPassThroughContext>

    • toJson<T>(data: T): Json<T>
    • Convert a javascript object into a JSON plain object. Serializes Dates into strings and removes keys with undefined values

      const a = toJson({ date: new Date(), test: undefined });

      // a will be { date: '2020-01 ...' };

      Type parameters

      • T

      Parameters

      • data: T

      Returns Json<T>

    application Functions

    • init<TApplication>(app: TApplication): Promise<TApplication>
    • Start all the Service objects in initOrder sequentially. If it has an array of Service, will start them in parallel.

      // Will start s1, s2 and s3 in that sequential order
      start({ initOrder: [s1, s2, s3] });

      // Will start s1 and s2, then start s3, s4 and s5 in parallel, and lastly start s6
      start({ initOrder: [s1, s2, [s3, s4, s5], s6] });

      Parameters

      Returns Promise<void>

    • Stop all the Service objects in initOrder sequentially, in reverse order from start

      // Will stop s3, s2 and s1 in that sequential order
      stop({ initOrder: [s1, s2, s3] });

      // Will stop s6, then s3, s4 and s5 in parallel, and lastly will stop s2 and s1 sequentially
      start({ initOrder: [s1, s2, [s3, s4, s5], s6] });

      Parameters

      Returns Promise<void>

    http Functions

    • isHttpError(item: unknown): item is HttpError
    • isSecurityOk(item: unknown): item is SecurityOk<any>
    • Create an application using an OpenApi schema. The api can be a filename (json or yaml) or a javascript object containing OpenApi Schema. You also provide an HttpListener for each path. As well as all security resolvers

      Type parameters

      • TContext: Empty

        pass the request properties that the app requires. Usually added by the middlewares

      Parameters

      Returns Promise<HttpListener<TContext>>

    • Use different routes to call different parts of the application.

      If you have route parameter in the path, like /test1/{id} would pass them down in the path property of the request.

      const listener:App = router(
      get('/route1/{id}', ({ path: { id }}) => {
      // ...
      }),
      post('/other-route', ({ body }) => {
      // ...
      })
      )

      Type parameters

      • TContext: Empty = Empty

        pass the request properties that the listener requires. Usually added by the middlewares

      Parameters

      Returns HttpListener<TContext>

    • securityError(body: { message: string }): HttpError
    • securityOk<TOapiAuthInfo>(authInfo: TOapiAuthInfo): SecurityOk<TOapiAuthInfo>
    • securityRedirect(location: string, __namedParameters: { body?: { message: string }; headers?: OutgoingHttpHeaders }): HttpError
    • serializeCookie(name: string, rawValue: string | number | boolean, options?: CookieOptions): string
    • Serialize data into a cookie header.

      Serialize the a name value pair into a cookie string suitable for http headers. An optional options object specified cookie parameters.

      serialize('foo', 'bar', { httpOnly: true }) => "foo=bar; httpOnly"

      Parameters

      • name: string
      • rawValue: string | number | boolean
      • options: CookieOptions = {}

      Returns string

    • toHttpRequest(incommingMessage: IncomingMessage): HttpContext
    • A component that parses the url and header information from the raw incommingMessage And adding host, protocol, headers, url and method properties

      Parameters

      • incommingMessage: IncomingMessage

      Returns HttpContext

    • toMultipartBoundary(contentType: undefined | string): string | undefined
    • Get the multipart boundary from contentType

      Parameters

      • contentType: undefined | string

        header from http request

      Returns string | undefined

      boundary string or undefined, if not found

    logger Functions

    • A generic logger middleware. Can be used with any resolver funciton, like http listener or queue worker.

      const withLogger = loggerMiddleware(console);

      new HttpListener({
      listener: withLogger(async ({ logger }) => {
      logger.info('test');
      })
      })

      Type parameters

      Parameters

      • logger: TLogger

        Logger instance, must implement info and error. You can use console to output to stdout

      Returns Middleware<LoggerContext<TLogger>>

    • withStaticMetadata<TLogger>(logger: TLogger, staticMetadata: LoggerMetadata): TLogger
    • Bake in some metadata for each logger call afterwards, reusing the same logger instance.

      Useful for adding trace tokens and the like

      const myLogger = console
      const myLoggerTraced = withStaticMetadata(myLogger, { traceToken: '123' });

      // Would output 'trace' with the traceToken metadata we've setup earlier.
      myLoggerTraced.info('test');

      Type parameters

      Parameters

      Returns TLogger

    Generated using TypeDoc