Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113287
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/tesla/middleware/path_params.ex b/lib/tesla/middleware/path_params.ex
index 059b7f3..8b27dbb 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.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/:([a-zA-Z]{1}[\w_]*)/
@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
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 1:16 AM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39197
Default Alt Text
(1 KB)
Attached To
Mode
R28 tesla
Attached
Detach File
Event Timeline
Log In to Comment