6
votes

I've setup a very simple Azure Function in C# to respond to an HttpTrigger. When I run the function locally following Microsoft Azure instructions, all I'm getting back is an empty 404 response.

I'm using Visual Studio 2017 v15.3 Preview with the Azure Function Tools extension installed. This is the code for my Azure Function:

[FunctionName("Func1")]        
public static async Task<object> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, WebHookType = "genericJson")]
    HttpRequestMessage req, 
    TraceWriter log)
{
    return req.CreateResponse(HttpStatusCode.OK);
}

When I run it locally (by right-clicking the VS project and going Debug > Start new instance) it seems to launch just fine. My function is recognized and the URL given for it is http://localhost:7071/api/Func1

However, When I GET or POST to the above URL (with a Content-Type header set to "application/json") I get back an empty 404 response. The Azure Functions CLI console outputs:

[6/12/2017 12:26:12 PM] Executing HTTP request: {

[6/12/2017 12:26:12 PM] "requestId": "ae247ea6-c055-40f5-a09c-40ea207cc785",

[6/12/2017 12:26:12 PM] "method": "GET",

[6/12/2017 12:26:12 PM] "uri": "/api/Func1"

[6/12/2017 12:26:12 PM] }

[6/12/2017 12:26:12 PM] Executed HTTP request: {

[6/12/2017 12:26:12 PM] "requestId": "ae247ea6-c055-40f5-a09c-40ea207cc785",

[6/12/2017 12:26:12 PM] "method": "GET",

[6/12/2017 12:26:12 PM] "uri": "/api/Func1",

[6/12/2017 12:26:12 PM] "authorizationLevel": "Anonymous"

[6/12/2017 12:26:12 PM] }

[6/12/2017 12:26:12 PM] Response details: {

[6/12/2017 12:26:12 PM] "requestId": "ae247ea6-c055-40f5-a09c-40ea207cc785",

[6/12/2017 12:26:12 PM] "status": "NotFound"

[6/12/2017 12:26:12 PM] }

Why am I getting a 404 and how can I fix this?

1

1 Answers

12
votes

You need to specify the methods parameter, e.g.

[HttpTrigger(AuthorizationLevel.Anonymous, "GET")]