FaasJS
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security

Documents / @faasjs/core / Http

Class: Http<TParams, TCookie, TSession>

HTTP lifecycle plugin that enriches invoke data with cookies, sessions, and response helpers.

The plugin skips non-api runtimes, parses JSON request bodies into params, removes the _ query param, turns invalid JSON into 400, persists session changes automatically, and wraps handler results in the FaasJS JSON response envelope. Session use requires cookie.session.secret in config or environment.

Example

import { Http } from '@faasjs/core'

const http = new Http({
  config: {
    cookie: {
      session: {
        key: 'session_id',
        secret: 'replace-me',
      },
    },
  },
})

Type Parameters

TParams

TParams extends Record<string, any> = any

Parsed HTTP params type injected into invoke data.

TCookie

TCookie extends Record<string, string> = any

Cookie map exposed by the cookie helper.

TSession

TSession extends Record<string, string> = any

Session map exposed by the session helper.

Implements

  • Plugin

Constructors

Constructor

new Http<TParams, TCookie, TSession>(config?): Http<TParams, TCookie, TSession>

Create an HTTP plugin instance.

Parameters

config?

HttpConfig

Optional plugin name and HTTP configuration overrides.

Returns

Http<TParams, TCookie, TSession>

Methods

onInvoke()

onInvoke(data, next): Promise<void>

Attach HTTP helpers, cookies, sessions, and response handling to invoke data.

The HTTP plugin also injects runtime helpers such as headers, body, params, cookie, and session before invoking the next handler in the chain. Successful values default to status 200, missing bodies default to 204, and response headers include JSON content type, no-cache, request id, and queued cookies.

Parameters

data

InvokeData

Invocation data for the current request.

next

Next

Continuation for the remaining invoke chain.

Returns

Promise<void>

Promise that resolves after response helpers are applied.

Implementation of

Plugin.onInvoke

onMount()

onMount(data, next): Promise<void>

Merge environment and function config into the plugin before first invoke.

Request-scoped logging is also available during mount through the runtime-injected logger.

Parameters

data

MountData

Mount data supplied by the parent function.

next

Next

Continuation for the remaining mount chain.

Returns

Promise<void>

Promise that resolves after config merging completes.

Throws

When function config is unavailable.

Implementation of

Plugin.onMount

Properties

config

config: object

Active HTTP plugin configuration after mount-time merging.

cookie?

optional cookie?: CookieOptions

Cookie and session configuration injected into invoke data.

name

readonly name: string = Name

Plugin instance name used in config lookup and logs.

Implementation of

Plugin.name

type

readonly type: "http" = 'http'

Stable plugin type identifier.

Implementation of

Plugin.type