Exling v0.1.0 Exling

Exling is a fluent HTTP request builder and executor for Elixir. It is intended to make it simpler to build HTTP client APIs, but should be handy any time you need to make an HTTP request. It isn’t an HTTTP client library, however, and leaves the actual request and response handling up to already established libraries.

Summary

Functions

Set the HTTP Accept header. Use :json, :form, :xml or :plain, or your custom string if none of those apply

Add the key/value pair to the HTTP headers. Additional calls for the same header type are appended

Set the base URI (or really as much URI information as you want)

Set the request body. Use a type option to save yourself the trouble of setting the content type for common values. In the case of :form or :json, your body data should be a map and will automatically be encoded as well. :xml will set the content type but you are on your own for encoding, and if you have other content encoding needs, just use body(my_body) and set the content type yourself with content_type or set

Set the client type to handle actual requests. Defaults to :httpoison

Set the HTTP Content-type header. Use :json, :form, :xml or :plain, or your custom string if none of those apply. Note that using body() with the :json, :form, or :xml options will set this for you, but if you need to override it for some reason call this later in the chain

Set the HTTP method to DELETE. See get for more info and an example

Set the method to GET and add to the path. The optional extra path info is handy for REST APIs that may have multiple paths to an object with the final bit being an ID that might change often

Set the HTTP method to HEAD. See get for more info and an example

Returns a new Exling.Request

Set the HTTP method to OPTIONS. See get for more info and an example

Set the HTTP method to PATCH. See get for more info and an example

Set the URI path. Exling will try to figure out slashes for you so a leading slash is optional

Set the HTTP method to POST. See get for more info and an example

Set query params with a map, keyword list, or key and value. Can be called multiple times to append new params

Sed the key/value pair to the HTTP headers. Additional calls for the same header type will replace any previous entry

Functions

accept(request, type)

Set the HTTP Accept header. Use :json, :form, :xml or :plain, or your custom string if none of those apply.

add(request, k, v)

Add the key/value pair to the HTTP headers. Additional calls for the same header type are appended.

base(request, base_uri)

Set the base URI (or really as much URI information as you want).

Examples

r = Exling.new |> Exling.base(“http://example.com”)

r = Exling.new |> Exling.base(“http://something.else.com/with/more/path”)

body(request, body)
body(request, body, atom)

Set the request body. Use a type option to save yourself the trouble of setting the content type for common values. In the case of :form or :json, your body data should be a map and will automatically be encoded as well. :xml will set the content type but you are on your own for encoding, and if you have other content encoding needs, just use body(my_body) and set the content type yourself with content_type or set.

Example

r = Exling.new |>
Exling.base("http://foo.com") |>
Exling.post() |>
Exling.body(%{my: "stuff"}, :json)
client(request, client)

Set the client type to handle actual requests. Defaults to :httpoison

content_type(request, type)

Set the HTTP Content-type header. Use :json, :form, :xml or :plain, or your custom string if none of those apply. Note that using body() with the :json, :form, or :xml options will set this for you, but if you need to override it for some reason call this later in the chain.

delete(request, path \\ nil)

Set the HTTP method to DELETE. See get for more info and an example.

get(request, path \\ nil)

Set the method to GET and add to the path. The optional extra path info is handy for REST APIs that may have multiple paths to an object with the final bit being an ID that might change often.

Examples

r = Exline.new |> Exling.base(“http://example.com”) |> Exling.path(“/things”) |> Exling.get(“1”)

head(request, path \\ nil)

Set the HTTP method to HEAD. See get for more info and an example.

new()

Returns a new Exling.Request.

new(base_uri)
options(request, path \\ nil)

Set the HTTP method to OPTIONS. See get for more info and an example.

patch(request, path \\ nil)

Set the HTTP method to PATCH. See get for more info and an example.

path(request, path)

Set the URI path. Exling will try to figure out slashes for you so a leading slash is optional.

Examples

r = Exling.new |> Exling.base(“http://example.com”) |> Exling.path(“/some/path”)

post(request, path \\ nil)

Set the HTTP method to POST. See get for more info and an example.

query(request, query)
query(request, k, v)

Set query params with a map, keyword list, or key and value. Can be called multiple times to append new params.

Example

r = Exling.new |>

  Exling.base("http://foo.com") |>
  Exling.query(foo: "bar") |>
  Exling.query(:boo, "far") |>
  Exling.query(Keyword.new([{:b, 1}, {:a, 2}])) |>
  Exling.query(%{and: "more"})
receive(request, options \\ [])

Send the request.

set(request, k, v)

Sed the key/value pair to the HTTP headers. Additional calls for the same header type will replace any previous entry.