Skip to content

req_template cannot mix templates with both colon (:) and curly brackets ({ }) #389

@stefanedwards

Description

@stefanedwards

The Microsoft Graph API has some curious endpoints, one of which requires the use of colon (:)

GET /sites/{hostname}:/{server-relative-path}

https://learn.microsoft.com/en-us/graph/api/site-get?view=graph-rest-1.0&tabs=http#access-a-site-by-server-relative-url

req_template fails miserable, as it believes the template uses colon-placeholders - not curly bracket placeholders:

req_template(request("http://example.http.com"), "/sites/{hostname}:/{server-relative-path}")
Error in env_has(env, name, inherit = TRUE) : 
  attempt to use zero-length variable name

Suggested solutions:

  1. Document this behaviour, most do.
  2. In template_type swap two first if conditions, so curly brackets are checked first, then brackets. Downside: Using a template without placeholders, but with a colon in the path will still fail.
  3. Check for :\\w+ in the grepl for colon, instead of just :.

I'll gladly make the changes and make a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions