Azure/azure-functions-java-library

HttpTrigger cannot be invoked using PATCH method

kdlugajczyk opened this issue · 1 comments

It seems that there is an issue with invoking http triggered functions with PATCH method. Problem occurs both in 2.0.0 and 2.0.1 versions.

@FunctionName("PatchMethodFunction")
public HttpResponseMessage run(
        @HttpTrigger(name = "req", methods = HttpMethod.PATCH, authLevel = AuthorizationLevel.ANONYMOUS) 
                HttpRequestMessage<Optional<String>> request,
        final ExecutionContext context) {

    return request.createResponseBuilder(HttpStatus.OK).build();
}

I cannot trigger the endpoint and as a console output I get:

PatchMethodFunction: [NULL] http://localhost:7071/PatchMethodFunction

If I specify all of the possible methods:

@HttpTrigger(name = "req", methods = {GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, CONNECT, TRACE}, authLevel = AuthorizationLevel.ANONYMOUS)

The result is following:

PatchMethodFunction: [GET,POST,PUT,NULL,DELETE,HEAD,OPTIONS,CONNECT,TRACE] http://localhost:7071/PatchMethodFunction

When I do not specify methods parameter at all, it's possible to invoke function with every method, including PATCH

@HttpTrigger(name = "req", authLevel = AuthorizationLevel.ANONYMOUS)

Hi @kdlugajczyk , I tried to reproduce the issue, I didn't see the issue you mentioned about patch. I am testing on version 2.0.1

image
image

    @FunctionName("HttpExample")
    public HttpResponseMessage run(
            @HttpTrigger(
                name = "req",
                methods = {HttpMethod.GET, HttpMethod.POST, HttpMethod.PATCH},
                authLevel = AuthorizationLevel.ANONYMOUS)
                HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger 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("Hello, " + name).build();
        }
    }

Please let me know if I missing something. Thanks.