Skip to content

Latest commit

 

History

History
86 lines (68 loc) · 2.4 KB

README.md

File metadata and controls

86 lines (68 loc) · 2.4 KB

holster

A Gun holster

Quickstart

$ make
$ ./rebar3 shell
erl> {ok, _} = application:ensure_all_started(holster).

Description:

holster makes the gun interaction simpler, by hiding out some of the fancy footwork required. Support for long running connections (http2), and simple requests. connection get's teared down for simple requests after each request.

( req/2/3/4/5 )

holster:req(req_type(), Uri :: string()) =
  {response, Resonse :: {resp_code() :: non_neg_integer(), 
                         gun:resp_headers(),
                         response() :: binary()} |
  {response, ErrResponse :: term()}

Example simple request

holster:req(get, "http://www.google.com").

Stay connected request:

holster:stay_connected_req(Uri :: string()) =
  {
     {ok, pid()}, {response, Resonse :: {resp_code() :: non_neg_integer(), 
                                         resp_headers(),
                                         response() :: binary()}} |
     {response, ErrResponse :: term()}
  }

and then all other subsequent requests made with the pid:

holster:another_request(get, Uri :: string(), PidOrOpts :: pid()) =
  {response, Resonse :: {resp_code() :: non_neg_integer(), 
                         resp_headers() :: proplists:proplist(),
                         response() :: binary()} | 
  {response, ErrResponse :: term()}

Basic erlang process approach

holster:simple_proc_req(req_type(), Uri :: string()) =
  {response, Resonse :: {resp_code() :: non_neg_integer(), 
                         resp_headers() :: proplists:proplist(),
                         response() :: binary()} | 
  {response, ErrResponse :: term()}

Websocket request:

ws_connect(uri_string:uri_string(), gun:opts()) = 
  {ok, pid(), gun:resp_headers()} | 
  {error, {ws_upgrade, timeout}}.

Websocket request example:

{ok, <0.167.0>,
    [{<<"upgrade">>, <<"websocket">>},
     {<<"connection">>, <<"Upgrade">>},
     {<<"sec-websocket-accept">>, <<"nRurElfkCM9Jf2Obkkcm5rqfpy8=">>},
     {<<"date">>, <<"Sun, 10 Mar 2024 13:33:34 GMT">>},
     {<<"server">>, <<"Python/3.12 websockets/12.0">>}]} = holster:ws_connect("ws:\/\/localhost:8765", #{}).

ok = holster:ws_req(<0.167.0>, {text, <<"test">>}).
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy