Tesla.OpenAPI.PathTemplate (tesla v1.18.1)

Copy Markdown View Source

A precompiled OpenAPI Path Templating path.

Tesla.OpenAPI.PathTemplate keeps the request path as a string while carrying a compiled representation that Tesla.Middleware.PathParams can use to avoid parsing the same path template on every request.

alias Tesla.OpenAPI.PathTemplate

template = PathTemplate.new!("/items/{id}")
path_params = Tesla.OpenAPI.PathParams.new!([Tesla.OpenAPI.PathParam.new!("id")])

private =
  %{}
  |> PathTemplate.put_private(template)
  |> Tesla.OpenAPI.PathParams.put_private(path_params)

Tesla.get(client, template.path,
  opts: [path_params: %{"id" => id}],
  private: private
)

Path templates follow the OpenAPI Path Templating syntax for {name} template expressions.

Summary

Types

t()

@opaque t()

Functions

new!(path)

@spec new!(String.t()) :: t()

put_private(template)

@spec put_private(t()) :: Tesla.Env.private()

Adds the compiled path template to Tesla.Env.private/0.

template = Tesla.OpenAPI.PathTemplate.new!("/items/{id}")
path_params = Tesla.OpenAPI.PathParams.new!([Tesla.OpenAPI.PathParam.new!("id")])

private =
  %{}
  |> Tesla.OpenAPI.PathTemplate.put_private(template)
  |> Tesla.OpenAPI.PathParams.put_private(path_params)

Tesla.get(client, template.path,
  opts: [path_params: %{"id" => id}],
  private: private
)

put_private(private, template)

@spec put_private(Tesla.Env.private(), t()) :: Tesla.Env.private()