You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -32,15 +32,15 @@ The following diagram depicts the relationship between the Functions host and a
32
32
- The web server executes the individual function, and returns a [response payload](#response-payload) to the Functions host.
33
33
- The Functions host proxies the response as an output binding payload to the target.
34
34
35
-
An Azure Functions app implemented as a custom handler must configure the *host.json* and *function.json* files according a few conventions.
35
+
An Azure Functions app implemented as a custom handler must configure the *host.json* and *function.json* files according to a few conventions.
36
36
37
37
## Application structure
38
38
39
39
To implement a custom handler, you need the following aspects in your application:
40
40
41
41
- A *host.json* file at the root of your app
42
42
- A *function.json* file for each function (inside a folder that matches the function name)
43
-
- A command, script, or executable which runs a web server
43
+
- A command, script, or executable, which runs a web server
44
44
45
45
The following diagram shows how these files look on the file system for a function named "order".
46
46
@@ -53,9 +53,9 @@ The following diagram shows how these files look on the file system for a functi
53
53
54
54
### Configuration
55
55
56
-
The application is configured via the *host.json* file. This file tells the Functions host where to send requests by pointing to a web server capable of processing HTTP events.
56
+
The application is configured via the *host.json* file. This file tells the Functions host where to send requests by pointing to a web server capable of processing HTTP events.
57
57
58
-
A custom handler is defined by configuring the *host.json* file with details on how to run the web server via the `httpWorker` section.
58
+
A custom handler is defined by configuring the *host.json* file with details on how to run the web server via the `httpWorker` section.
59
59
60
60
```json
61
61
{
@@ -67,7 +67,8 @@ A custom handler is defined by configuring the *host.json* file with details on
67
67
}
68
68
}
69
69
```
70
-
The `httpWorker` section points to a target as defined by the `defaultExecutablePath`. The execution target may either be a command, executable or file where the web server is implemented.
70
+
71
+
The `httpWorker` section points to a target as defined by the `defaultExecutablePath`. The execution target may either be a command, executable, or file where the web server is implemented.
71
72
72
73
For scripted apps, `defaultExecutablePath` points to the script language's runtime and `defaultWorkerPath` points to the script file location. The following example shows how a JavaScript app in Node.js is configured as a custom handler.
73
74
@@ -98,7 +99,7 @@ You can also pass arguments using the `arguments` array:
98
99
}
99
100
```
100
101
101
-
Arguments are necessary for many debugging setups. See the [Debugging](#debugging) section for more detail.
102
+
Arguments are necessary for many debugging setups. See the [Debugging](#debugging) section for more detail.
102
103
103
104
> [!NOTE]
104
105
> The *host.json* file must be at the same level in the directory structure as the running web server. Some languages and toolchains may not place the this file at the application root by default.
@@ -115,7 +116,7 @@ When used with a custom handler, the *function.json* contents are no different f
115
116
116
117
The request payload for pure HTTP functions is the raw HTTP request payload. Pure HTTP functions are defined as functions with no input or output bindings, that return an HTTP response.
117
118
118
-
Any other type of function that includes either input, output bindings or is triggered via an event source other than HTTP have a custom request payload.
119
+
Any other type of function that includes either input, output bindings or is triggered via an event source other than HTTP have a custom request payload.
119
120
120
121
The following code represents a sample request payload. The payload includes a JSON payload with two members: `Data` and `Metadata`.
121
122
@@ -140,13 +141,13 @@ Given the bindings defined in the following *function.json* file:
140
141
"type": "queue",
141
142
"direction": "out",
142
143
"queueName": "messages-outgoing",
143
-
"connection": "AzureWebJobsStorage"
144
+
"connection": "AzureWebJobsStorage"
144
145
}
145
146
]
146
147
}
147
148
```
148
149
149
-
A request payload similar to this example is returned:
150
+
A request payload similar to this example is returned:
150
151
151
152
```json
152
153
{
@@ -183,16 +184,16 @@ See the [example for a sample payload](#server-implementation).
183
184
184
185
## Examples
185
186
186
-
Custom handlers can be implemented in any language that supports HTTP events. While Azure Functions [fully supports JavaScript and Node.js](./functions-reference-node.md), the following examples show how to implement a custom handler using JavaScript in Node.js for the purposes of instruction.
187
+
Custom handlers can be implemented in any language that supports HTTP events. While Azure Functions [fully supports JavaScript and Node.js](./functions-reference-node.md), the following examples show how to implement a custom handler using JavaScript in Node.js for the purposes of instruction.
187
188
188
189
> [!TIP]
189
190
> While being a guide for learning how to implement a custom handler in other languages, the Node.js-based examples shown here may also be useful if you wanted to run a Functions app in a non-supported version of Node.js.
190
191
191
192
## HTTP-only function
192
193
193
-
The following example demonstrates how to configure a simple HTTP-triggered function with no additional bindings or outputs. The scenario implemented in this example features a function named `http` that accepts a `GET` or `POST` .
194
+
The following example demonstrates how to configure an HTTP-triggered function with no additional bindings or outputs. The scenario implemented in this example features a function named `http` that accepts a `GET` or `POST` .
194
195
195
-
The following snippet represents how a a request to the function is composed.
196
+
The following snippet represents how a request to the function is composed.
In this example, Express is used to create a web server to handle HTTP events and is set to listen for requests via the `FUNCTIONS_HTTPWORKER_PORT`.
270
+
In this example, Express is used to create a web server to handle HTTP events and is set to listen for requests via the `FUNCTIONS_HTTPWORKER_PORT`.
270
271
271
-
The function is defined at the path of `/hello`. `GET` requests are handled by returning a simple JSON object, and `POST` requests have access to the request body via `req.body`.
272
+
The function is defined at the path of `/hello`. `GET` requests are handled by returning a simple JSON object, and `POST` requests have access to the request body via `req.body`.
272
273
273
274
The route for the order function here is `/hello` and not `/api/hello` because the Functions host is proxying the request to the custom handler.
In this example, Express is used to create a web server to handle HTTP events and is set to listen for requests via the `FUNCTIONS_HTTPWORKER_PORT`.
373
+
In this example, Express is used to create a web server to handle HTTP events and is set to listen for requests via the `FUNCTIONS_HTTPWORKER_PORT`.
374
374
375
375
The function is defined at the path of `/order` . The route for the order function here is `/order` and not `/api/order` because the Functions host is proxying the request to the custom handler.
376
376
@@ -385,9 +385,9 @@ By setting `message` equal to the message that came in from the request, and `re
385
385
386
386
## Debugging
387
387
388
-
To debug your Functions custom handler app you need to add arguments appropriate for the language and runtime to enable debugging.
388
+
To debug your Functions custom handler app, you need to add arguments appropriate for the language and runtime to enable debugging.
389
389
390
-
For instance, to debug a Node.js application, the `--inspect` flag is passed as an argument in the *host.json* file.
390
+
For instance, to debug a Node.js application, the `--inspect` flag is passed as an argument in the *host.json* file.
391
391
392
392
```json
393
393
{
@@ -441,7 +441,7 @@ A custom handler can be deployed to any Azure Functions hosting option. If your
441
441
## Restrictions
442
442
443
443
- Custom handlers are not supported in Linux consumption plans.
0 commit comments