2

I am trying to create a simple function that will take a parameter on the get and return a list of categories based on that parameter.

However, I cannot find any useful documentation about routing or passing through parameters so this is what I have - I just need a pointer in how to access the website parameter (and if the route is correct)

public static class GetCategoriesCRUDFunction
{
    [FunctionName("CategoriesFunction")]
    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "{website}")]HttpRequestMessage request, TraceWriter log) // is this how to set up a route or do I need to do attribute routing?
    {
        IService service = new Service();

        var categories = await service.GetCategories(website);  // how do I get this website parameter from the querystring - do I need to use something like httpcontext?

        return request.CreateResponse(HttpStatusCode.OK, categories);
    }
}

1 Answer 1

5

You're almost there. To actually get the value from the querystring, add the parameter to the Run method:

[FunctionName("CategoriesFunction")]
public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = "{website}")] HttpRequestMessage request, 
    string website, 
    TraceWriter log)

You might want to add something in the route... By default, all HttpTriggered functions have a route prefix of api. So you could, for instance, have the route be Route = "categories/{website}" so the URL will be https://<function_app_url>/api/categories/<websitename>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.