View Source Tesla.Middleware.PathParams (tesla v1.9.0)

Use templated URLs with provided parameters in either Phoenix style (:id) or OpenAPI style ({id}).

Useful when logging or reporting metrics per URL.

Parameter Values

Parameter values may be struct/0 or must implement the Enumerable protocol and produce {key, value} tuples when enumerated.

Parameter Name Restrictions

Phoenix style parameters may contain letters, numbers, or underscores, matching this regular expression:


OpenAPI style parameters may contain letters, numbers, underscores, or hyphens (-), matching this regular expression:


In either case, parameters that begin with underscores (_), hyphens (-), or numbers (0-9) are ignored and left as-is.


defmodule MyClient do
  use Tesla

  plug Tesla.Middleware.BaseUrl, ""
  plug Tesla.Middleware.Logger # or some monitoring middleware
  plug Tesla.Middleware.PathParams

  def user(id) do
    params = [id: id]
    get("/users/{id}", opts: [path_params: params])

  def posts(id, post_id) do
    params = [id: id, post_id: post_id]
    get("/users/:id/posts/:post_id", opts: [path_params: params])