Module: HttpFp

Includes:
Utils
Included in:
Curl, Httpie, NetHttp
Defined in:
lib/http_fp.rb,
lib/http_fp/version.rb

Defined Under Namespace

Modules: Curl, Httpie, NetHttp, Rack

Constant Summary collapse

VERSION =
"0.0.1"
@@empty_req =
{proto: "HTTP/1.1", host: "http://example.com", path: "/", query: {}, header: {}, method: "GET", body: ""}
@@empty_resp =
{status: nil, header: {}, body: {}}
@@run_ =

underscore because run conflicts with run fn in minitest

-> fn { fn.(@@empty_req) }
@@verb =
-> verb, req { req.merge({method: verb.to_s.upcase}) }.curry
@@with_host =
-> host, req { req[:host] = host; req }.curry
@@with_path =
-> path, req { req[:path] = path; req }.curry
@@with_query =
-> params, req { req[:query] = params ; req }.curry
@@with_json =
-> hash, req { req[:body] = hash.to_json; req }.curry
@@with_headers =
-> header, req { req[:header] = header ; req }.curry
@@add_headers =
-> header, req { req[:header].merge!(header); req }.curry
@@with_basic_auth =
-> user_name, pwd, req do 
  encoded = Base64.strict_encode64("#{user_name}:#{pwd}")
  req >>+ add_headers.({"Authorization" => "Basic #{encoded}"})
end.curry
@@json_resp =
Utils.at.(:body) >>~ Utils.parse_json
-> a { $stdout.puts a.pretty_inspect ; a }
@@to_uri =
-> req {
uri = URI(req.fetch(:host))
req[:query] && uri.query = URI.encode_www_form(req[:query])
uri.path = req[:path]
uri}
@@json_headers =
{"accept"     => "application/json",
'Content-Type' => 'application/json',
"user-agent" => "paw/3.0.11 (macintosh; os x/10.11.6) gcdhttprequest"}