Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
teamon committed Jul 22, 2019
1 parent b633126 commit a1ec6a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ This is very similar to how [Plug Router](https://github.com/elixir-plug/plug#th
- [`Tesla.Middleware.MethodOverride`](https://hexdocs.pm/tesla/Tesla.Middleware.MethodOverride.html) - set X-Http-Method-Override
- [`Tesla.Middleware.Logger`](https://hexdocs.pm/tesla/Tesla.Middleware.Logger.html) - log requests (method, url, status, time)
- [`Tesla.Middleware.KeepRequest`](https://hexdocs.pm/tesla/Tesla.Middleware.KeepRequest.html) - keep request body & headers
- [`Tesla.Middleware.PathParams`](https://hexdocs.pm/tesla/Tesla.Middleware.PathParams.html) - use templated URLs

#### Formats
- [`Tesla.Middleware.FormUrlencoded`](https://hexdocs.pm/tesla/Tesla.Middleware.FormUrlencoded.html) - urlencode POST body parameter, useful for POSTing a map/keyword list
Expand Down
24 changes: 24 additions & 0 deletions lib/tesla/middleware/path_params.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
defmodule Tesla.Middleware.PathParams do
@behaviour Tesla.Middleware

@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
```
"""

@rx ~r/:([\w_]+)/

@doc false
@impl true
def call(env, next, _) do
url = build_url(env.url, env.opts[:path_params])
Expand Down

0 comments on commit a1ec6a0

Please sign in to comment.