Maxwell (maxwell v2.4.0) View Source

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

Link to this section Summary

Functions

DELETE! http method.

DELETE! http method.

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.

PUT! http method.

TRACE http method without request body.

TRACE! http method without request body.

TRACE! http method without request body.

Link to this section Functions

Link to this function

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

View Source

DELETE method.

  • conn - %Maxwell.Conn{}.

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

Link to this function

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

View Source

DELETE! http method.

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

Link to this function

delete!(conn, normal_statuses)

View Source

DELETE! http method.

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

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

Link to this function

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

View Source

GET http method without request body.

  • conn - %Maxwell.Conn{}

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

Link to this function

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

View Source

GET! http method without request body.

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

Link to this function

get!(conn, normal_statuses)

View Source

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{}.

Link to this function

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

View Source

HEAD http method without request body.

  • conn - %Maxwell.Conn{}

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

Link to this function

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

View Source

HEAD! http method without request body.

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

Link to this function

head!(conn, normal_statuses)

View Source

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{}.

Link to this function

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

View Source

OPTIONS http method without request body.

  • conn - %Maxwell.Conn{}

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

Link to this function

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

View Source

OPTIONS! http method without request body.

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

Link to this function

options!(conn, normal_statuses)

View Source

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{}.

Link to this function

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

View Source

PATCH method.

  • conn - %Maxwell.Conn{}.

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

Link to this function

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

View Source

PATCH! http method.

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

Link to this function

patch!(conn, normal_statuses)

View Source

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{}.

Link to this function

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

View Source

POST method.

  • conn - %Maxwell.Conn{}.

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

Link to this function

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

View Source

POST! http method.

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

Link to this function

post!(conn, normal_statuses)

View Source

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{}.

Link to this function

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

View Source

PUT method.

  • conn - %Maxwell.Conn{}.

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

Link to this function

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

View Source

PUT! http method.

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

Link to this function

put!(conn, normal_statuses)

View Source

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{}.

Link to this function

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

View Source

TRACE http method without request body.

  • conn - %Maxwell.Conn{}

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

Link to this function

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

View Source

TRACE! http method without request body.

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

Link to this function

trace!(conn, normal_statuses)

View Source

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{}.