Skip to content

Route path parameters cannot be retrieved easily #198

@eduardomourar

Description

@eduardomourar

Investigative information

Please provide the following:

  • Timestamp: 2018-09-15
  • Function App version (1.0 or 2.0-beta): 2.0-beta
  • Function App name: Local
  • Function name(s) (as appropriate): test-list
  • Invocation ID: Local
  • Region: Local

Repro steps

  1. Create sample function based on source code below
  2. Hit api /api/list/product_a?validate=true

Expected behavior

I expected to have both query and path parameters:

{
  "params": {
    "product": "product_a"
  },
  "query": {
    "validate": "true"
  }
}

Actual behavior

Instead I have the params property containing the query parameters:

{
  "method": "POST",
  "url": "http://localhost:7071/api/list/product_a?validate=true",
  "headers": {
    "connection": "keep-alive"
  },
  "params": {
    "validate": "true"
  },
  "query": {},
  "get_body": ""
}

Known workarounds

I have created a branch based on dev to make some changes to the http binding code and it is available here.

Let me know if this is relevant for the project and I will make a PR for it.

Related information

Provide any related information

  • Sample source files
Source
## function.json
{
  "scriptFile": "__init_py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "request",
      "methods": [
        "post"
      ],
      "route": "list/{product}"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}
## __init_py
def main(request: azure.functions.HttpRequest) -> azure.functions.HttpResponse:

    params = {}
    if hasattr(request, 'params'):
        params = dict(request.params)
    query = {}
    if hasattr(request, 'query'):
        query = dict(request.query)
    headers = dict(request.headers)
    return json.dumps({
        'method': request.method,
        'url': request.url,
        'headers': headers,
        'params': params,
        'query': query,
        'get_body': request.get_body().decode(),
    })

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions