1
0
Fork
You've already forked ex_link_header
0
Parse HTTP link headers in Elixir
  • Elixir 100%
Find a file
2025年06月28日 19:46:28 +02:00
config low effort modernisation 2025年06月28日 19:46:28 +02:00
lib Fix credo --strict 2016年10月16日 09:36:31 +01:00
test Escape path and params 2016年06月29日 18:23:38 +01:00
.gitignore add support for building a Link header 2016年05月15日 19:11:05 +02:00
.travis.yml credo --strict to fail 2016年10月16日 09:31:55 +01:00
LICENSE Add build status and licence details 2016年01月19日 23:10:11 +00:00
mix.exs low effort modernisation 2025年06月28日 19:46:28 +02:00
mix.lock low effort modernisation 2025年06月28日 19:46:28 +02:00
README.md Bump to v0.0.5 2016年06月28日 17:56:50 +01:00

ExLinkHeader

Parse or build HTTP Link headers in Elixir.

Usage

ExLinkHeader.parse!("<https://api.github.com/user/simonrand/repos?per_page=100&page=2>; rel=\"next\", <https://api.github.com/user/simonrand/repos?page=3&per_page=100>; rel=\"last\", <https://api.github.com/user/simonrand/repos?page=1&per_page=100>; rel=\"first\"")
#=> %ExLinkHeader{
 first: %ExLinkHeaderEntry{host: "api.github.com",
 path: "/user/simonrand/repos", params: %{page: "1", per_page: "100"},
 scheme: "https", attributes: %{},
 url: "https://api.github.com/user/simonrand/repos?page=1&per_page=100"},
 next: %ExLinkHeaderEntry{host: "api.github.com", path: "/user/simonrand/repos",
 params: %{page: "2", per_page: "100"}, scheme: "https", attributes: %{},
 url: "https://api.github.com/user/simonrand/repos?per_page=100&page=2"},
 last: %ExLinkHeaderEntry{host: "api.github.com", path: "/user/simonrand/repos",
 params: %{page: "3", per_page: "100"}, scheme: "https", attributes: %{},
 url: "https://api.github.com/user/simonrand/repos?page=3&per_page=100"},
 ...}
ExLinkHeader.parse!("")
#=> ** (ExLinkHeader.ParseError) Parse error: no valid links to parse
%ExLinkHeader{
 first: %ExLinkHeaderEntry{host: "api.github.com",
 path: "/user/simonrand/repos", params: %{page: "1", per_page: "100"},
 scheme: "https", attributes: %{},
 url: "https://api.github.com/user/simonrand/repos?page=1&per_page=100"},
 next: %ExLinkHeaderEntry{host: "api.github.com", path: "/user/simonrand/repos",
 params: %{page: "2", per_page: "100"}, scheme: "https", attributes: %{},
 url: "https://api.github.com/user/simonrand/repos?per_page=100&page=2"},
 last: %ExLinkHeaderEntry{host: "api.github.com", path: "/user/simonrand/repos",
 params: %{page: "3", per_page: "100"}, scheme: "https", attributes: %{},
 url: "https://api.github.com/user/simonrand/repos?page=3&per_page=100"}} |> ExLinkHeader.build
#=> "<https://api.github.com//user/simonrand/repos?page=3&per_page=100>; rel=\"last\", <https://api.github.com//user/simonrand/repos?page=2&per_page=100>; rel=\"next\", <https://api.github.com//user/simonrand/repos?page=1&per_page=100>; rel=\"first\""

Note a change to the parse method in v0.0.5

A struct is now returned for each link header as opposed to a map.

Note a change in v0.0.4

Links with no page or per_page param previously returned nil by default for both these params, even if they did not exist - this is now no longer the case, page and per_page are now treated like any other query params. To return nil for these values you can supply defaults for any param when calling parse to ensure default values are returned, for example:

ExLinkHeader.parse!("<https://api.github.com/user/simonrand/repos?per_page=100>; rel=\"next\"", %{page: nil})
#=> %ExLinkHeader{next: %ExLinkHeaderEntry{attributes: %{}, host: "api.github.com",
 params: %{page: nil, per_page: "100"}, path: "/user/simonrand/repos",
 scheme: "https",
 url: "https://api.github.com/user/simonrand/repos?per_page=100"}}

(Note: this is the struct based response for versions > 0.0.4)

Code Status

Build Status

Installation

The package can be installed as:

  1. Add ex_link_header to your list of dependencies in mix.exs:

    def deps do [{:ex_link_header, "~> 0.0.5"}] end

  2. Ensure ex_link_header is started before your application:

    def application do [applications: [:ex_link_header]] end

License

Released under the Apache 2 License.

See LICENSE for more information.