Created
July 15, 2021 10:11
-
-
Save Gogetter/e61749324147d61808899a3991ab2a3c to your computer and use it in GitHub Desktop.
basic http trigger function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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