Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thiamsantos/linkex

Encode and decode HTTP Link headers.
https://github.com/thiamsantos/linkex

Last synced: 4 days ago
JSON representation

Encode and decode HTTP Link headers.

Awesome Lists containing this project

README

        

# Linkex

[![Travis](https://img.shields.io/travis/thiamsantos/linkex.svg)](https://travis-ci.org/thiamsantos/linkex)
[![Hex.pm](https://img.shields.io/hexpm/v/linkex.svg)](https://hex.pm/packages/linkex)
[![Docs](https://img.shields.io/badge/hex-docs-green.svg)](https://hexdocs.pm/linkex)

> Encode and decode HTTP Link headers.

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)

## Install

The package can be installed by adding `linkex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:linkex, "~> 0.1.0"}
]
end
```

## Usage

```elixir
iex> Linkex.encode("; rel="next", ; rel="last")
{:ok, %LinkHeader{
last: %Entry{
target:
%URI{
authority: "api.github.com",
fragment: nil,
host: "api.github.com",
path: "/user/13632762/repos",
port: 443,
query: "client_id=1&client_secret=2&page=3&per_page=100",
scheme: "https",
userinfo: nil
}
},
next: %Entry{
target:
%URI{
authority: "api.github.com",
fragment: nil,
host: "api.github.com",
path: "/user/13632762/repos",
port: 443,
query: "client_id=1&client_secret=2&page=2&per_page=100",
scheme: "https",
userinfo: nil
}
}
}}

iex> Linkex.decode(%LinkHeader{
last: %Entry{
target:
%URI{
authority: "api.github.com",
fragment: nil,
host: "api.github.com",
path: "/user/13632762/repos",
port: 443,
query: "client_id=1&client_secret=2&page=3&per_page=100",
scheme: "https",
userinfo: nil
}
},
next: %Entry{
target:
%URI{
authority: "api.github.com",
fragment: nil,
host: "api.github.com",
path: "/user/13632762/repos",
port: 443,
query: "client_id=1&client_secret=2&page=2&per_page=100",
scheme: "https",
userinfo: nil
}
}
})

{:ok, "; rel="next", ; rel="last"}
```

## Contributing

See the [contributing file](CONTRIBUTING.md).

## License

[Apache License, Version 2.0](LICENSE) © [Thiago Santos](https://github.com/thiamsantos)