Skip to content

Commit

Permalink
Samples for HTTP Binding (Azure#30).
Browse files Browse the repository at this point in the history
  • Loading branch information
Junyi Yi committed Jul 20, 2018
1 parent 6eeab26 commit 68d16d0
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* {@literal @}FunctionName("hello")
* public HttpResponseMessage<String> helloFunction(
* {@literal @}HttpTrigger(name = "req",
* methods = {"get"},
* methods = {HttpMethod.GET},
* authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request) {
* ....
* }</pre>
Expand All @@ -54,6 +54,36 @@
* endpoints to be specified, and for these endpoints to be parameterized with arguments being bound to arguments
* provided to the function at runtime.</p>
*
* <p>The 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.</p>
*
* <pre>
* {@literal @}FunctionName("readHttpName")
* public String readName(
* {@literal @}HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
* final HttpRequestMessage&lt;Optional&lt;String&gt;&gt; request) {
* String name = request.getBody().orElseGet(() -&gt; request.getQueryParameters().get("name"));
* return name == null ?
* "Please pass a name on the query string or in the request body" :
* "Hello " + name;
* }
* </pre>
*
* <p>The following example shows a webhook trigger binding in Java function. The function logs GitHub issue comments.</p>
*
* <pre>
* {@literal @}FunctionName("logGithubIssues")
* public String logIssues(
* {@literal @}HttpTrigger(name = "req", webHookType = WebHookType.GITHUB)
* final String content,
* ExecutionContext context) {
* context.getLogger().info("WebHook was triggered!");
* context.getLogger().info("Content is " + content);
* return "New GitHub comment: " + content;
* }
* </pre>
*
* @see com.microsoft.azure.functions.HttpRequestMessage
* @see com.microsoft.azure.functions.HttpResponseMessage
* @since 1.0.0
Expand Down Expand Up @@ -96,7 +126,7 @@
* {@literal @}FunctionName("routeTest")
* public HttpResponseMessage&lt;String&gt; routeTest(
* {@literal @}HttpTrigger(name = "req",
* methods = {"get"},
* methods = {HttpMethod.GET},
* authLevel = AuthorizationLevel.ANONYMOUS,
* route = "products/{category:alpha}/{id:int}") HttpRequestMessage&lt;Optional&lt;String&gt;&gt; request,
* {@literal @}BindingName("category") String category,
Expand Down

0 comments on commit 68d16d0

Please sign in to comment.