maxwell v2.2.2 Maxwell

The maxwell specification.

There are two kind of usages: basic usage and advanced middleware usage.

Basic Usage

## Returns Origin IP, for example %{"origin" => "127.0.0.1"}
"http://httpbin.org/ip"
|> Maxwell.Conn.new()
|> Maxwell.get!()
|> Maxwell.Conn.get_resp_body()
|> Poison.decode!()

Find all get_*&put_* helper functions by h Maxwell.Conn.xxx

Advanced Middleware Usage(Create API Client).

   defmodule Client do
     use Maxwell.Builder, ~w(get)a
     adapter Maxwell.Adapter.Ibrowse

     middleware Maxwell.Middleware.BaseUrl,   "http://httpbin.org"
     middleware Maxwell.Middleware.Opts,      [connect_timeout: 5000]
     middleware Maxwell.Middleware.Headers,   %{"User-Agent" => "zhongwencool"}
     middleware Maxwell.Middleware.Json

     ## Returns origin IP, for example "127.0.0.1"
     def ip() do
       "/ip"
       |> new()
       |> get!()
       |> get_resp_body("origin")
     end

     ## Generates n random bytes of binary data, accepts optional seed integer parameter
     def get_random_bytes(size) do
       "/bytes/#{size}"
       |> new()
       |> get!()
       |> get_resp_body(&to_string/1)
     end
  end

Summary

Functions

DELETE http method without request body

DELETE! http method without request body

DELETE! http method without request body

GET http method without request body

GET! http method without request body

GET! http method without request body

HEAD http method without request body

HEAD! http method without request body

HEAD! http method without request body

OPTIONS http method without request body

OPTIONS! http method without request body

OPTIONS! http method without request body

PATCH! http method

PATCH! http method

POST! http method

POST! http method

PUT! http method

TRACE http method without request body

TRACE! http method without request body

TRACE! http method without request body

Functions

delete(conn \\ %Maxwell.Conn{})

DELETE http method without request body.

  • conn - %Maxwell.Conn{}

Returns {:ok, %Maxwell.Conn{}} or {:error, reason_term, %Maxwell.Conn{}}.

delete!(conn \\ %Maxwell.Conn{})

DELETE! http method without request body.

Returns %Maxwell.Conn{} or raise %MaxWell.Error{} when status not in [200..299].

delete!(conn, normal_statuses)

DELETE! http method without request body.

  • conn - see delete/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.

get(conn \\ %Maxwell.Conn{})

GET http method without request body.

  • conn - %Maxwell.Conn{}

Returns {:ok, %Maxwell.Conn{}} or {:error, reason_term, %Maxwell.Conn{}}.

get!(conn \\ %Maxwell.Conn{})

GET! http method without request body.

Returns %Maxwell.Conn{} or raise %MaxWell.Error{} when status not in [200..299].

get!(conn, normal_statuses)

GET! http method without request body.

  • conn - see get/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.

head(conn \\ %Maxwell.Conn{})

HEAD http method without request body.

  • conn - %Maxwell.Conn{}

Returns {:ok, %Maxwell.Conn{}} or {:error, reason_term, %Maxwell.Conn{}}.

head!(conn \\ %Maxwell.Conn{})

HEAD! http method without request body.

Returns %Maxwell.Conn{} or raise %MaxWell.Error{} when status not in [200..299].

head!(conn, normal_statuses)

HEAD! http method without request body.

  • conn - see head/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.

options(conn \\ %Maxwell.Conn{})

OPTIONS http method without request body.

  • conn - %Maxwell.Conn{}

Returns {:ok, %Maxwell.Conn{}} or {:error, reason_term, %Maxwell.Conn{}}.

options!(conn \\ %Maxwell.Conn{})

OPTIONS! http method without request body.

Returns %Maxwell.Conn{} or raise %MaxWell.Error{} when status not in [200..299].

options!(conn, normal_statuses)

OPTIONS! http method without request body.

  • conn - see options/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.

patch(conn \\ %Maxwell.Conn{})

PATCH method.

  • conn - %Maxwell.Conn{}.

Returns {:ok, %Maxwell.Conn{}} or {:error, reason, %Maxwell.Conn{}}

patch!(conn \\ %Maxwell.Conn{})

PATCH! http method.

Return %Maxwell.Conn{} or raise %Maxwell.Error{} when status not in [200.299]

patch!(conn, normal_statuses)

PATCH! http method.

  • conn - see patch/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.

post(conn \\ %Maxwell.Conn{})

POST method.

  • conn - %Maxwell.Conn{}.

Returns {:ok, %Maxwell.Conn{}} or {:error, reason, %Maxwell.Conn{}}

post!(conn \\ %Maxwell.Conn{})

POST! http method.

Return %Maxwell.Conn{} or raise %Maxwell.Error{} when status not in [200.299]

post!(conn, normal_statuses)

POST! http method.

  • conn - see post/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.

put(conn \\ %Maxwell.Conn{})

PUT method.

  • conn - %Maxwell.Conn{}.

Returns {:ok, %Maxwell.Conn{}} or {:error, reason, %Maxwell.Conn{}}

put!(conn \\ %Maxwell.Conn{})

PUT! http method.

Return %Maxwell.Conn{} or raise %Maxwell.Error{} when status not in [200.299]

put!(conn, normal_statuses)

PUT! http method.

  • conn - see put/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.

trace(conn \\ %Maxwell.Conn{})

TRACE http method without request body.

  • conn - %Maxwell.Conn{}

Returns {:ok, %Maxwell.Conn{}} or {:error, reason_term, %Maxwell.Conn{}}.

trace!(conn \\ %Maxwell.Conn{})

TRACE! http method without request body.

Returns %Maxwell.Conn{} or raise %MaxWell.Error{} when status not in [200..299].

trace!(conn, normal_statuses)

TRACE! http method without request body.

  • conn - see trace/1
  • normal_statuses - the specified status which not raise exception, for example: [200, 201]

Returns %Maxwell.Conn{} or raise %MaxWell.Error{}.