View Source ExHttpLink (ex_http_link v0.1.4)

Library for the HTTP Link header as specified in RFC 5988 "Web Linking".

Link to this section Summary

Functions

Generate a Link header.

Parses the given binary as links_parsec.

Parse a Link header.

Link to this section Functions

Generate a Link header.

examples

Examples

iex> ExHttpLink.generate [ { "http://example.com", {"rel", "example"}, {"rev", "test"} } ]
~S(<http://example.com>; rel="example"; rev="test")

iex> ExHttpLink.generate [ { "http://example.com/a b c?x=y", {"rel", "example"} } ]
~S(<http://example.com/a%20b%20c?x=y>; rel="example")

iex> ExHttpLink.generate [ { "http://example.com/a%20b%20c?x=y", {"rel", "example"} } ]
~S(<http://example.com/a%20b%20c?x=y>; rel="example")

iex> ExHttpLink.generate [ { "http://example.com", {"rel", "example"} }, { "te.st", {"a", "b"}, {"c", ""} } ]
~S(<http://example.com>; rel="example", <te.st>; a="b"; c="")

iex> ExHttpLink.generate [ { "te.st", {"a", ~S(hello "world")} } ]
~S(<te.st>; a="hello%20%22world%22")

Parse a Link header.

examples

Examples

iex> ExHttpLink.parse ~S(<http://example.com>; rel="example"; rev=test)
{:ok, [ { "http://example.com", {"rel", "example"}, {"rev", "test"} } ]}

iex> ExHttpLink.parse ~S(<yolo.swag>; whatEver="", <http://dev/null>; rel=next)
{:ok, [ { "yolo.swag", {"whatEver", ""} }, { "http://dev/null", {"rel", "next"} } ]}

iex> ExHttpLink.parse ~S(<yolo.swag>; title="some \" thing \" %22stuff%22 ")
{:ok, [ { "yolo.swag", {"title", "some \" thing \" \"stuff\" "} } ]}

iex> ExHttpLink.parse ~S(          < http://example.com >;rel=  "example";      title ="example dot com"     )
{:ok, [ { "http://example.com", {"rel", "example"}, {"title", "example dot com"} } ]}

iex> ExHttpLink.parse ~S(<wat>; title*=UTF-8'de'n%c3%a4chstes%20Kapitel)
{:ok, [ { "wat", {"title*", "UTF-8'de'n%c3%a4chstes%20Kapitel"}  } ]}