Module hackney

Data Types

client()

abstract datatype: client()

client_ref()

client_ref() = term()

url()

url() = #hackney_url{} | binary()

Function Index

body/1Return the full body sent with the response.
body/2Return the full body sent with the response as long as the body length doesn't go over MaxLength.
cancel_request/1Extract raw informations from the client context This feature can be useful when you want to create a simple proxy, rerouting on the headers and the status line and continue to forward the connection for example.
close/1close the client.
connect/1
connect/2
connect/3connect a socket and create a client state.
connect/4
controlling_process/2Assign a new controlling process Pid to Client.
cookies/1
finish_send_body/1
location/1return the requested location.
pause_stream/1pause a response stream, the stream process will hibernate and be woken later by the resume function.
redirect_location/1
request/1make a request.
request/2make a request.
request/3make a request.
request/4make a request.
request/5make a request.
request_info/1get request info.
resume_stream/1resume a paused response stream, the stream process will be awoken.
send_body/2send the request body until eob.
send_multipart_body/2send a multipart body until eof Possible value are :
  • eof: end the multipart request
  • {file, Path}: to stream a file
  • {file, Path, ExtraHeaders}: to stream a file
  • {data, Name, Content}: to send a full part
  • {data, Name, Content, ExtraHeaders}: to send a full part
  • {part, Name, Len}: to start sending a part with a known length in a streaming fashion
  • {part, Name, Len, ExtraHeader}: to start sending a part in a streaming fashion
  • {part, Name}: to start sending a part without length in a streaming fashion
  • {part, Name, ExtraHeader}: to start sending a part without lengthin a streaming fashion
  • {part_bin, Bin}: To send part of part
  • {part, eof}: To notify the end of the part
  • {mp_mixed, Name, MixedBoundary}: To notify we start a part with a a mixed multipart content
  • {mp_mixed_eof, MixedBoundary}: To notify we end a part with a a mixed multipart content
Note: You can calculate the full length of a multipart stream using the function hackney_multipart:len_mp_stream/2 .
send_request/2send a request using the current client state.
send_request/3send a request using the current client state and pass new options to it.
setopts/2set client options.
skip_body/1skip the full body.
skip_multipart/1Stream the response body.
start_response/1start a response.
stop_async/1stop to receive asynchronously.
stream_body/1Stream the response body.
stream_multipart/1Stream the response body.
stream_next/1continue to the next stream message.

Function Details

body/1

body(Ref::client_ref()) -> {ok, binary()} | {error, atom()} | {error, {closed, binary()}}

Return the full body sent with the response.

body/2

body(Ref::client_ref(), MaxLength::non_neg_integer() | infinity) -> {ok, binary()} | {error, atom()} | {error, {closed, binary()}}

Return the full body sent with the response as long as the body length doesn't go over MaxLength.

cancel_request/1

cancel_request(Ref::client_ref()) -> {ok, {atom(), inet:socket(), binary(), hackney_response:response_state()}} | {error, term()}

Extract raw informations from the client context This feature can be useful when you want to create a simple proxy, rerouting on the headers and the status line and continue to forward the connection for example.

return: {ResponseState, Transport, Socket, Buffer} | {error, Reason}

close/1

close(Ref) -> any()

close the client

connect/1

connect(URL) -> any()

connect/2

connect(Hackney_url, Options) -> any()

connect/3

connect(Transport, Host, Port) -> any()

connect a socket and create a client state.

connect/4

connect(Transport, Host, Port, Options) -> any()

controlling_process/2

controlling_process(Ref::client_ref(), Pid::pid()) -> ok | {error, closed | not_owner | atom()}

Assign a new controlling process Pid to Client.

cookies/1

cookies(Headers::list()) -> list()

finish_send_body/1

finish_send_body(Ref) -> any()

location/1

location(Ref::client_ref()) -> binary()

return the requested location

pause_stream/1

pause_stream(Ref::client_ref()) -> ok | {error, req_not_found}

pause a response stream, the stream process will hibernate and be woken later by the resume function

redirect_location/1

redirect_location(Headers) -> any()

request/1

request(URL::url() | binary() | list()) -> {ok, integer(), list(), client_ref()} | {ok, integer(), list()} | {error, term()}

make a request

request/2

request(Method::term(), URL::url() | binary() | list()) -> {ok, integer(), list(), client_ref()} | {ok, integer(), list()} | {error, term()}

make a request

request/3

request(Method::term(), URL::url() | binary() | list(), Headers::list()) -> {ok, integer(), list(), client_ref()} | {ok, integer(), list()} | {error, term()}

make a request

request/4

request(Method::term(), URL::url() | binary() | list(), Headers::list(), Body::term()) -> {ok, integer(), list(), client_ref()} | {ok, integer(), list()} | {error, term()}

make a request

request/5

request(Method::term(), Hackney_url::url() | binary() | list(), Headers0::list(), Body::term(), Options0::list()) -> {ok, integer(), list(), client_ref()} | {ok, integer(), list()} | {ok, client_ref()} | {error, term()}

make a request

Args:

Note: instead of doing hackney:request(Method, ...) you can also do hackney:Method(...) if you prefer to use the REST syntax.

Return:

request_info/1

request_info(Ref::client_ref()) -> list()

get request info

resume_stream/1

resume_stream(Ref::client_ref()) -> ok | {error, req_not_found}

resume a paused response stream, the stream process will be awoken

send_body/2

send_body(Ref::client_ref(), Body::term()) -> ok | {error, term()}

send the request body until eob. It's issued after sending a request using the request and send_request functions.

send_multipart_body/2

send_multipart_body(Ref::client_ref(), Body::term()) -> ok | {error, term()}

send a multipart body until eof Possible value are :

Note: You can calculate the full length of a multipart stream using the function hackney_multipart:len_mp_stream/2 .

send_request/2

send_request(Ref, Req) -> any()

send a request using the current client state

send_request/3

send_request(Ref, Req, Options) -> any()

send a request using the current client state and pass new options to it.

setopts/2

setopts(Ref::client_ref(), Options::list()) -> ok

set client options. Options are: - async: to fetch the response asynchronously - {async, once}: to receive the response asynchronously once time. To receive the next message use the function hackney:stream_next/1. - {stream_to, pid()}: to set the pid where the messages of an asynchronous response will be sent. - {follow_redirect, bool()} : if true a redirection will be followed when the response is received synchronously - {force_redirect, bool()} : if true a 301/302 redirection will be followed even on POST. - {max_redirect, integer()} the maximum number of redirections that will be followed

skip_body/1

skip_body(Ref::client_ref()) -> ok | {error, atom()}

skip the full body. (read all the body if needed).

skip_multipart/1

skip_multipart(Ref::client_ref()) -> ok | {error, term()}

Stream the response body.

start_response/1

start_response(Ref::client_ref()) -> {ok, integer(), list(), client_ref()} | {ok, client_ref()} | {error, term()}

start a response. Useful if you stream the body by yourself. It will fetch the status and headers of the response. and return

stop_async/1

stop_async(Ref::client_ref()) -> ok | {error, req_not_found} | {error, term()}

stop to receive asynchronously.

stream_body/1

stream_body(Ref::client_ref()) -> {ok, binary()} | done | {error, term()}

Stream the response body.

stream_multipart/1

stream_multipart(Ref::client_ref()) -> {headers, list()} | {body, binary()} | eof | end_of_part | {error, term()}

Stream the response body.

Return:

stream_next/1

stream_next(Ref::client_ref()) -> ok | {error, req_not_found}

continue to the next stream message. Only use it when {async, once} is set in the client options.


Generated by EDoc