Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Context

Hierarchy

Indexable

[key: string]: any

Custom properties.

Properties

accept

accept: any

body

body: any

Get/Set response body.

cookies

cookies: Cookies

FaaS Cookies Object

env

env: string

etag

etag: string

Get/Set the ETag of a response. This will normalize the quotes if necessary.

this.response.etag = 'md5hashsum';
this.response.etag = '"md5hashsum"';
this.response.etag = 'W/"123456789"';
param
api

public

header

header: object

Return request header.

Type declaration

  • [key: string]: string

headers

headers: object

Return request header, alias as request.header

Type declaration

  • [key: string]: string

Optional hooks

host

host: string

Get parsed host from event

hostname

hostname: string

Get parsed host from event

ip

ip: string

Request remote address.

lastModified

lastModified: Date

Get the Last-Modified date in Date form, if it exists. Set the Last-Modified date using a string or a Date.

this.response.lastModified = new Date();
this.response.lastModified = '2013-09-13';

length

length: number

Return parsed response Content-Length when present. Set Content-Length field to n.

logger

logger: ILogger

method

method: string

Get request method.

originContext

originContext: any

originEvent

originEvent: any

FaaS original event object.

params

params: object

Get parsed params

Type declaration

  • [key: string]: string

path

path: string

Get request pathname.

query

query: object

Get parsed query-string.

Type declaration

  • [key: string]: any

req

Alias to this.request

request

FaaS http request object

requestContext

requestContext: MidwayRequestContainer

res

Alias to this.Response

response

FaaS http response object

startTime

startTime: number

status

status: number

Get/Set response status code.

type

type: string

Return the response mime type void of parameters such as "charset".

Set Content-Type response header with type through mime.lookup() when it does not contain a charset.

Examples:

this.type = '.html';
this.type = 'html';
this.type = 'json';
this.type = 'application/json';
this.type = 'png';

url

url: string

Get/Set request URL.

Methods

accepts

  • accepts(): string[] | boolean
  • accepts(...types: string[]): string | boolean
  • accepts(types: string[]): string | boolean
  • Check if the given type(s) is acceptable, returning the best match when true, otherwise undefined, in which case you should respond with 406 "Not Acceptable".

    The type value may be a single mime type string such as "application/json", the extension name such as "json" or an array ["json", "html", "text/plain"]. When a list or array is given the best match, if any is returned.

    Examples:

    // Accept: text/html
    this.accepts('html');
    // => "html"
    
    // Accept: text/*, application/json
    this.accepts('html');
    // => "html"
    this.accepts('text/html');
    // => "text/html"
    this.accepts('json', 'text');
    // => "json"
    this.accepts('application/json');
    // => "application/json"
    
    // Accept: text/*, application/json
    this.accepts('image/png');
    this.accepts('png');
    // => undefined
    
    // Accept: text/*;q=.5, application/json
    this.accepts(['html', 'json']);
    this.accepts('html', 'json');
    // => "json"
    

    Returns string[] | boolean

  • Parameters

    • Rest ...types: string[]

    Returns string | boolean

  • Parameters

    • types: string[]

    Returns string | boolean

acceptsCharsets

  • acceptsCharsets(): string[] | boolean
  • acceptsCharsets(...charsets: string[]): string | boolean
  • acceptsCharsets(charsets: string[]): string | boolean

acceptsEncodings

  • acceptsEncodings(): string[] | boolean
  • acceptsEncodings(...encodings: string[]): string | boolean
  • acceptsEncodings(encodings: string[]): string | boolean

acceptsLanguages

  • acceptsLanguages(): string[] | boolean
  • acceptsLanguages(...langs: string[]): string | boolean
  • acceptsLanguages(langs: string[]): string | boolean

append

  • append(field: string, val: string | string[]): void

get

  • get(field: string): string
  • Return request header. If the header is not set, will return an empty string.

    The Referrer header field is special-cased, both Referrer and Referer are interchangeable.

    Examples:

    this.get('Content-Type');
    // => "text/plain"
    
    this.get('content-type');
    // => "text/plain"
    
    this.get('Something');
    // => ''
    

    Parameters

    • field: string

    Returns string

getLogger

  • getLogger(name?: string): ILogger

is

  • is(...types: string[]): string | boolean
  • is(types: string[]): string | boolean
  • Check if the incoming request contains the "Content-Type" header field, and it contains any of the give mime types. If there is no request body, null is returned. If there is no content type, false is returned. Otherwise, it returns the first type that matches.

    Examples:

    // With Content-Type: text/html; charset=utf-8
    this.is('html'); // => 'html'
    this.is('text/html'); // => 'text/html'
    this.is('text/*', 'application/json'); // => 'text/html'
    
    // When Content-Type is application/json
    this.is('json', 'urlencoded'); // => 'json'
    this.is('application/json'); // => 'application/json'
    this.is('html', 'application/*'); // => 'application/json'
    
    this.is('html'); // => false
    

    Parameters

    • Rest ...types: string[]

    Returns string | boolean

  • Parameters

    • types: string[]

    Returns string | boolean

redirect

  • redirect(url: string, alt?: string): void

remove

  • remove(field: string): void

set

  • set(field: object): void
  • set(field: string, val: string | string[]): void

Generated using TypeDoc