Shot

shot is a small HTTP client library for Erlang

Hex.pm Version

Goals

Shot aims to provide a simple way for REST calls

Documentation

For examples will be used shot and test services for requests:

Build & Run

$ git clone https://github.com/vkatsuba/shot.git
$ cd shot
$ wget https://s3.amazonaws.com/rebar3/rebar3
$ chmod u+x ./rebar3
$ ./rebar3 shell

Dialyzer

$ ./rebar3 dialyzer

Run Common Tests

# See result in _build/test/logs after tests pass
$ ./rebar3 do xref, ct

Clean Project

$ ./rebar3 clean

Add shot to project: Rebar3

PUT

% PUT without headers
shot:put("http://httpbin.org/put").
% PUT with headers
Data = #{
    u => "https://httpbin.org/anything",              % URL string, eg: "http://test.com"
    h => #{"Authorization" => "Bearer dXNlcjpwYXNz"}  % Headers
}.
shot:put(Data).

GET

% GET without headers
shot:get("http://httpbin.org/get").
% GET with headers
Data = #{
    u => "https://httpbin.org/bearer",                % URL string, eg: "http://test.com"
    h => #{"Authorization" => "Bearer dXNlcjpwYXNz"}  % Headers
}.
shot:get(Data).

POST

% POST without headers
shot:post("http://httpbin.org/post").
% POST with headers
Data = #{
    u => "https://httpbin.org/anything",                        % URL string, eg: "http://test.com"
    b => "{\"foo\":[\"bing\",2.3,true]}",                       % Body data
    ct => "application/json",                                   % Content-Type, eg: "text/html"
    h => #{"Authorization" => "Basic dmthdHN1YmE6JDFxMnczZTQk"} % Headers
}.
shot:post(Data).

DELETE

% DELETE without headers
shot:delete("http://httpbin.org/delete").
% DELETE with headers
Data = #{
    u => "https://httpbin.org/anything",              % URL string, eg: "http://test.com"
    h => #{"Authorization" => "Bearer dXNlcjpwYXNz"}  % Headers
}.
shot:delete(Data).

multipart/form-data

To be continued ...

Support

v.katsuba.dev@gmail.com