Aller au contenu principal
Version: Next

FaaSHTTPRequest

Hierarchy

  • ContextDelegatedRequest
    • FaaSHTTPRequest

Index

Properties

accept

accept: any

body

body: any

Get parsed request body from event

header

header: {}

Return request header.

headers

headers: {}

Return request header, alias as request.header

host

host: string

Get parsed host from event

hostname

hostname: string

Get parsed host from event

ip

ip: string

Request remote address.

method

method: string

Get request method.

originalUrl

originalUrl: string

params

params: {}

Get parsed params

path

path: string

Get request pathname.

pathParameters

pathParameters: any

Get Parsed path parameters from event

query

query: {}

Get parsed query-string.

url

url: string

Get/Set request URL.

Methods

accepts

  • accepts(): boolean | string[]
  • 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"

acceptsCharsets

  • acceptsCharsets(): boolean | string[]
  • acceptsCharsets(...charsets: string[]): string | boolean
  • acceptsCharsets(charsets: string[]): string | boolean
  • Return accepted charsets or best fit based on charsets.

    Given Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5 an array sorted by quality is returned:

    ['utf-8', 'utf-7', 'iso-8859-1']

acceptsEncodings

  • acceptsEncodings(): boolean | string[]
  • acceptsEncodings(...encodings: string[]): string | boolean
  • acceptsEncodings(encodings: string[]): string | boolean
  • Return accepted encodings or best fit based on encodings.

    Given Accept-Encoding: gzip, deflate an array sorted by quality is returned:

    ['gzip', 'deflate']

acceptsLanguages

  • acceptsLanguages(): boolean | string[]
  • acceptsLanguages(...langs: string[]): string | boolean
  • acceptsLanguages(langs: string[]): string | boolean
  • Return accepted languages or best fit based on langs.

    Given Accept-Language: en;q=0.8, es, pt an array sorted by quality is returned:

    ['es', 'pt', 'en']

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');
    // => ''

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