Skip to content

Instantly share code, notes, and snippets.

@Gogetter
Created July 15, 2021 10:11
Show Gist options
  • Save Gogetter/e61749324147d61808899a3991ab2a3c to your computer and use it in GitHub Desktop.
Save Gogetter/e61749324147d61808899a3991ab2a3c to your computer and use it in GitHub Desktop.
basic http trigger function
@FunctionName("download")
public HttpResponseMessage downloadFile(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("FileDownloadHttpTrigger processed a request.");
// Parse query parameter
final String query = request.getQueryParameters().get("name");
final String name = request.getBody().orElse(query);
if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
.body("Please pass a name on the query string or in the request body")
.build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body("Welcome, " + name).build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment