HTTP trigger#
In this document#
Overview#
The HTTP trigger is the only trigger created by default if not configured (by default, it has 1 worker). This trigger
handles incoming HTTP requests at container port 8080, assigning workers to incoming requests. If a worker is not
available, a 503 error is returned.
Attributes#
Path |
Type |
Description |
|---|---|---|
port |
int |
The NodePort (or equivalent) on which the function will serve HTTP requests. If empty, chooses a random port within the platform range. When running on k8s, this only has effect if serviceType of type |
string |
The host to which the ingress maps. |
|
ingresses.(name).hostTemplate |
string |
The template used to generate an ingress host (use |
ingresses.(name).paths |
list of strings |
The paths that the ingress handles. Variables of the form |
readBufferSize |
int |
Per-connection buffer size for reading requests. |
maxRequestBodySize |
int |
Maximum request body size. (default: 4MiB) |
reduceMemoryUsage |
bool |
Reduces memory usage at the cost of higher CPU usage if set to true. |
cors.enabled |
bool |
|
cors.allowOrigins |
list of strings |
Indicates that the CORS response can be shared with requesting code from the specified origin ( |
cors.allowMethods |
list of strings |
The allowed HTTP methods, which can be used when accessing the resource ( |
cors.allowHeaders |
list of strings |
The allowed HTTP headers, which can be used when accessing the resource ( |
cors.allowCredentials |
bool |
|
cors.preflightMaxAgeSeconds |
int |
The number of seconds in which the results of a preflight request can be cached in a preflight result cache ( |
string |
(Kubernetes only) Kubernetes |
|
disablePortPublishing |
bool |
(Docker only) Allow disabling publishing the function container port on the host network |
streamingFlushPeriod |
string (duration) |
When the response body is streamed, the trigger flushes the response buffer to the client at most every this period (e.g. |
Examples#
With 4 workers and a maximum body size of 1 KB -
triggers:
myHttpTrigger:
numWorkers: 4
kind: "http"
attributes:
maxRequestBodySize: 1024
With a predefined port number -
triggers:
myHttpTrigger:
kind: "http"
attributes:
port: 32001
With ingresses -
triggers:
myHttpTrigger:
kind: "http"
attributes:
# See "Invoking Functions By Name With Kubernetes Ingresses" for more details
# on configuring ingresses
ingresses:
templated-host:
# e.g.: "my-func.some-namespace.nuclioio.com
hostTemplate: "{{ .ResourceName }}.{{ Namespace }}.nuclioio.com"
paths:
- "/"
http:
host: "host.nuclio"
paths:
- "/first/path"
- "/second/path"
http2:
paths:
- "MyFunctions/{{.Name}}/{{.Version}}"
With CORS -
triggers:
myCORSHttpTrigger:
kind: "http"
attributes:
cors:
enabled: true
allowOrigins:
- "foo.bar"
allowHeaders:
- "Accept"
- "Content-Length"
- "Content-Type"
- "X-nuclio-log-level"
- "MyCustomAllowedRequestHeader"
allowMethods:
- "GET"
- "HEAD"
- "POST"
- "PATCH"
allowCredentials: false
preflightMaxAgeSeconds: 3600
With streaming flush period (for streamed response bodies) -
triggers:
myHttpTrigger:
kind: "http"
attributes:
streamingFlushPeriod: "1s"