azure-docs-sdk-java/docs-ref-autogen/com.microsoft.azure.functio...

76 строки
10 KiB
YAML

### YamlMime:JavaType
uid: "com.microsoft.azure.functions.annotation.HttpTrigger"
fullName: "com.microsoft.azure.functions.annotation.HttpTrigger"
name: "HttpTrigger"
nameWithType: "HttpTrigger"
summary: "The HttpTrigger annotation is applied to Azure functions that will be triggered by a call to the HTTP endpoint that the function is located at."
syntax: "public interface **HttpTrigger**</br> implements <xref href=\"java.lang.annotation.Annotation?alt=java.lang.annotation.Annotation&text=Annotation\" data-throw-if-not-resolved=\"False\" />"
methods:
- uid: "com.microsoft.azure.functions.annotation.HttpTrigger.authLevel()"
fullName: "com.microsoft.azure.functions.annotation.HttpTrigger.authLevel()"
name: "authLevel()"
nameWithType: "HttpTrigger.authLevel()"
summary: "Determines what keys, if any, need to be present on the request in order to invoke the function."
modifiers:
- "abstract"
syntax: "public abstract AuthorizationLevel authLevel()"
desc: "Determines what keys, if any, need to be present on the request in order to invoke the function. The authorization level can be one of the following values:\n\n * **anonymous**: No API key is required.\n * **function**: A function-specific API key is required. This is the default value if none is provided.\n * **admin**: The master key is required.\n\nFor more information, see the [documentation about authorization keys][].\n\n\n[documentation about authorization keys]: https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook#authorization-keys"
returns:
description: "An <xref uid=\"com.microsoft.azure.functions.annotation.AuthorizationLevel\" data-throw-if-not-resolved=\"false\" data-raw-source=\"AuthorizationLevel\"></xref> value representing the level required to access the\n function."
type: "<xref href=\"com.microsoft.azure.functions.annotation.AuthorizationLevel?alt=com.microsoft.azure.functions.annotation.AuthorizationLevel&text=AuthorizationLevel\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.microsoft.azure.functions.annotation.HttpTrigger.dataType()"
fullName: "com.microsoft.azure.functions.annotation.HttpTrigger.dataType()"
name: "dataType()"
nameWithType: "HttpTrigger.dataType()"
summary: "Defines how Functions runtime should treat the parameter value."
modifiers:
- "abstract"
syntax: "public abstract String dataType()"
desc: "Defines how Functions runtime should treat the parameter value. Possible values are:\n\n * \"\": get the value as a string, and try to deserialize to actual parameter type like POJO\n * string: always get the value as a string\n * binary: get the value as a binary data, and try to deserialize to actual parameter type byte\\[\\]"
returns:
description: "The dataType which will be used by the Functions runtime."
type: "<xref href=\"java.lang.String?alt=java.lang.String&text=String\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.microsoft.azure.functions.annotation.HttpTrigger.methods()"
fullName: "com.microsoft.azure.functions.annotation.HttpTrigger.methods()"
name: "methods()"
nameWithType: "HttpTrigger.methods()"
summary: "An array of the HTTP methods to which the function responds."
modifiers:
- "abstract"
syntax: "public abstract HttpMethod[] methods()"
desc: "An array of the HTTP methods to which the function responds. If not specified, the function responds to all HTTP methods."
returns:
description: "An array containing all valid HTTP methods."
type: "<xref href=\"com.microsoft.azure.functions.HttpMethod?alt=com.microsoft.azure.functions.HttpMethod&text=HttpMethod\" data-throw-if-not-resolved=\"False\" />[]"
- uid: "com.microsoft.azure.functions.annotation.HttpTrigger.name()"
fullName: "com.microsoft.azure.functions.annotation.HttpTrigger.name()"
name: "name()"
nameWithType: "HttpTrigger.name()"
summary: "The variable name used in function code for the request or request body."
modifiers:
- "abstract"
syntax: "public abstract String name()"
desc: "The variable name used in function code for the request or request body."
returns:
description: "The variable name used in function code for the request or request body."
type: "<xref href=\"java.lang.String?alt=java.lang.String&text=String\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.microsoft.azure.functions.annotation.HttpTrigger.route()"
fullName: "com.microsoft.azure.functions.annotation.HttpTrigger.route()"
name: "route()"
nameWithType: "HttpTrigger.route()"
summary: "Defines the route template, controlling which request URLs your function will respond to."
modifiers:
- "abstract"
syntax: "public abstract String route()"
desc: "Defines the route template, controlling which request URLs your function will respond to. The default value if no route is provided is the function name specified in the <xref uid=\"com.microsoft.azure.functions.annotation.FunctionName\" data-throw-if-not-resolved=\"false\" data-raw-source=\"FunctionName\"></xref> annotation, applied to each Azure Function.\n\nBy default when you create a function for an HTTP trigger, or WebHook, the function is addressable with a route of the form `http://<yourapp>.azurewebsites.net/api/<funcname>`. You can customize this route using this route property. For example, a route of `\"products/{category:alpha}/{id:int}\"` would mean that the function is now addressable with the following route instead of the original route: `http://<yourapp>.azurewebsites.net/api/products/electronics/357`, which allows the function code to support two parameters in the address: category and id. By specifying the route in this way, developers can then add the additional route arguments as arguments into the function by using the <xref uid=\"com.microsoft.azure.functions.annotation.BindingName\" data-throw-if-not-resolved=\"false\" data-raw-source=\"BindingName\"></xref> annotation. For example:\n\n```java\n@FunctionName(\"routeTest\")\n public HttpResponseMessage<String> routeTest(\n @HttpTrigger(name = \"req\",\n methods = {HttpMethod.GET},\n authLevel = AuthorizationLevel.ANONYMOUS,\n route = \"products/{category:alpha}/{id:int}\") \n HttpRequestMessage<Optional<String>> request,\n @BindingName(\"category\") String category,\n @BindingName(\"id\") int id,\n final ExecutionContext context\n ) {\n ....\n context.getLogger().info(\"We have \" + category + \" with id \" + id);\n ....\n }\n```\n\nFor more details on the route syntax, refer to the [ online documentation][online documentation].\n\n\n[online documentation]: https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions"
returns:
description: "The route template to use for the annotated function."
type: "<xref href=\"java.lang.String?alt=java.lang.String&text=String\" data-throw-if-not-resolved=\"False\" />"
type: "interface"
desc: "The HttpTrigger annotation is applied to Azure functions that will be triggered by a call to the HTTP endpoint that the function is located at. The HttpTrigger annotation should be applied to a method parameter of one of the following types:\n\n * <xref uid=\"com.microsoft.azure.functions.HttpRequestMessage\" data-throw-if-not-resolved=\"false\" data-raw-source=\"HttpRequestMessage < T >\"></xref>\n * Any native Java types such as int, String, byte\\[\\]\n * Nullable values using Optional<T>\n * Any POJO type\n\nFor example:\n\n```java\n@FunctionName(\"hello\")\n public HttpResponseMessage<String> helloFunction(\n @HttpTrigger(name = \"req\",\n methods = {HttpMethod.GET},\n authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request\n ) {\n ....\n }\n```\n\nIn this code snippet you will observe that we have a function annotated with `@FunctionName(\"hello\")`, which indicates that this function will be available at the endpoint /api/hello. The name of the method itself, in this case `helloFunction` is irrelevant for all intents and purposes related to Azure Functions. Note however that the method return type is <xref uid=\"com.microsoft.azure.functions.HttpResponseMessage\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.microsoft.azure.functions.HttpResponseMessage\"></xref>, and that the first argument into the function is an <xref uid=\"com.microsoft.azure.functions.HttpRequestMessage\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.microsoft.azure.functions.HttpRequestMessage\"></xref> with generic type `Optional`. This indicates that the body of the request will potentially contain a String value.\n\nMost important of all however is the `@HttpTrigger` annotation that has been applied to this argument. In this annotation you'll note that it has been given a name, as well as told what type of requests it supports (in this case, only HTTP GET requests), and that the <xref uid=\"com.microsoft.azure.functions.annotation.AuthorizationLevel\" data-throw-if-not-resolved=\"false\" data-raw-source=\"AuthorizationLevel\"></xref> is anonymous, allowing access to anyone who can call the endpoint.\n\nThe `HttpTrigger` can be further customised by providing a custom <xref uid=\"com.microsoft.azure.functions.annotation.HttpTrigger.route()\" data-throw-if-not-resolved=\"false\" data-raw-source=\"#route()\"></xref>, which allows for custom endpoints to be specified, and for these endpoints to be parameterized with arguments being bound to arguments provided to the function at runtime.\n\nThe following example shows a Java function that looks for a name parameter either in the query string (HTTP GET) or the body (HTTP POST) of the HTTP request. Notice that the return value is used for the output binding, but a return value attribute isn't required.\n\n```java\n@FunctionName(\"readHttpName\")\n public String readName(\n @HttpTrigger(name = \"req\", \n methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)\n final HttpRequestMessage<Optional<String>> request) {\n String name = request.getBody().orElseGet(() -> request.getQueryParameters().get(\"name\"));\n return name == null ?\n \"Please pass a name on the query string or in the request body\" :\n \"Hello \" + name;\n }\n```"
implements:
- "<xref href=\"java.lang.annotation.Annotation?alt=java.lang.annotation.Annotation&text=Annotation\" data-throw-if-not-resolved=\"False\" />"
metadata: {}
package: "com.microsoft.azure.functions.annotation"
artifact: com.microsoft.azure.functions:azure-functions-java-library:1.3.1