Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/tesla/middleware/path_params.ex b/lib/tesla/middleware/path_params.ex
index 60d012f..0e7e28b 100644
--- a/lib/tesla/middleware/path_params.ex
+++ b/lib/tesla/middleware/path_params.ex
@@ -1,42 +1,42 @@
defmodule Tesla.Middleware.PathParams do
@moduledoc """
Use templated URLs with separate params.
Useful when logging or reporting metric per URL.
## Example usage
```
defmodule MyClient do
use Tesla
plug Tesla.Middleware.BaseURl, "https://api.example.com"
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])
end
end
```
"""
@behaviour Tesla.Middleware
- @rx ~r/:([\w_]+)/
+ @rx ~r/:([a-zA-Z_]+)/
@impl Tesla.Middleware
def call(env, next, _) do
url = build_url(env.url, env.opts[:path_params])
Tesla.run(%{env | url: url}, next)
end
defp build_url(url, nil), do: url
defp build_url(url, params) do
Regex.replace(@rx, url, fn match, key ->
to_string(params[String.to_existing_atom(key)] || match)
end)
end
end

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 26, 12:20 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40124
Default Alt Text
(1 KB)

Event Timeline