Skip to content

Commit df6b370

Browse files
Merge pull request #305013 from mattchenderson/http-testing
Adding HTTP trigger testing
2 parents 4c7b244 + f766154 commit df6b370

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

articles/azure-functions/functions-bindings-http-webhook-trigger.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,39 @@ Webhook authorization is handled by the webhook receiver component, part of the
12351235
* **Query string**: The provider passes the key name in the `clientid` query string parameter, such as `https://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>?clientid=<KEY_NAME>`.
12361236
* **Request header**: The provider passes the key name in the `x-functions-clientid` header.
12371237

1238+
## Invoke HTTP triggers
1239+
1240+
You can invoke your HTTP-triggered functions using an HTTP client. The examples in this section use [`curl`](https://github.com/curl/curl), but you can use any HTTP client tool that keeps your data secure. For more information, see [HTTP test tools](functions-develop-local.md#http-test-tools).
1241+
1242+
The request you need to make might be different between a local version of your code and when hosted in Azure. By default, when you run your project using the Azure Functions Core Tools, access key authorization requirements are removed. However, any requirements you've configured will still be enforced when hosted.
1243+
1244+
### Invoke locally
1245+
1246+
The [Azure Functions Core Tools](./functions-develop-local.md) registers a `localhost` endpoint for your function app, which you can use to invoke your functions. During application startup, the specific port being used is displayed in the console. The output also lists the available functions, and for each HTTP-triggered function, the output also includes the function's route template.
1247+
1248+
Use this information to construct the URL to provide to your API client. You also need to specify any headers, parameters, and request body information your function requires. The following example sends an HTTP POST request with a JSON body:
1249+
1250+
```bash
1251+
curl --request POST http://localhost:7071/api/Function1 --header "Content-Type: application/json" --data '{"message":"test data"}'
1252+
```
1253+
1254+
### Invoke in Azure
1255+
1256+
When invoking an HTTP-triggered function hosted in Azure, you need to consider your networking configuration. The HTTP client must have network access to the app, so if you have [inbound networking restrictions](./functions-networking-options.md#inbound-networking-features) enabled, the client might need to be within a virtual network or specific IP ranges. Your domain configuration determines the base URL you need to use for the request.
1257+
1258+
> [!NOTE]
1259+
> Newly created function apps can generate a unique default host name that uses the naming convention `<app-name>-<random-hash>.<region>.azurewebsites.net`. An example is `myapp-ds27dh7271aah175.westus-01.azurewebsites.net`. Existing app names remain unchanged.
1260+
>
1261+
> For more information, see the [blog post about creating an app with a unique default host name](https://techcommunity.microsoft.com/blog/appsonazureblog/secure-unique-default-hostnames-ga-on-app-service-web-apps-and-public-preview-on/4303571).
1262+
1263+
Unless you selected the anonymous [authorization level](#http-auth) in your trigger definition, your request may also need to [include an access key](./function-keys-how-to.md#use-access-keys).
1264+
1265+
The following example sends an HTTP POST request with a function body, including the access key in the query string:
1266+
1267+
```bash
1268+
curl --request POST "https://<your-function-app-base-url>/api/Function1?code=<your-function-key>" --header "Content-Type: application/json" --data '{"message":"test data"}'
1269+
```
1270+
12381271
## Content types
12391272

12401273
Passing binary and form data to a non-C# function requires that you use the appropriate content-type header. Supported content types include `octet-stream` for binary data and [multipart types](https://www.iana.org/assignments/media-types/media-types.xhtml#multipart).

0 commit comments

Comments
 (0)