Simplehttp
HTTP client for Elixir without dependencies
Install / Use
/learn @alexandrubagu/SimplehttpREADME
SimpleHttp

Unlike other projects / libraries, SimpleHttp doesn't have other dependencies
<table> <tbody> <tr> <th>SimpleHttp</th> <th> <a href="https://github.com/myfreeweb/httpotion">myfreeweb/httpotion</a> </th> <th> <a href="https://github.com/edgurgel/httpoison">edgurgel/httpoison</a> </th> </tr> <tr> <td valign="top"> <pre class="vicinity rich-diff-level-zero"> $ mix app.tree simplehttp └── elixir </pre> </td> <td valign="top"> <pre class="vicinity rich-diff-level-zero"> $ mix app.tree httpotion ├── elixir ├── ssl │ ├── crypto │ └── public_key │ ├── asn1 │ └── crypto └── ibrowse </pre> </td> <td valign="top"> <pre class="vicinity rich-diff-level-zero"> $ mix app.tree httpoison ├── elixir └── hackney ├── crypto ├── asn1 ├── public_key │ ├── asn1 │ └── crypto ├── ssl │ ├── crypto │ └── public_key ├── idna ├── mimerl ├── certifi ├── ssl_verify_fun │ └── ssl └── metrics </pre> </td> </tr> </tbody> </table>Hex Installation
- Add
simplehttpto your list of dependencies inmix.exs:
def deps do
[{:simplehttp, "~> 0.5.1"}]
end
Usage
Note:You can load SimpleHttp into the Elixir REPL by executing this command from the root of your project:
$ iex -S mix
Simple GET Request
{:ok, response} = SimpleHttp.get "http://jsonplaceholder.typicode.com/posts/1"
IO.inspect response
{:ok,
%SimpleHttp.Response{
body: "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}",
headers: [
{'cache-control', 'public, max-age=14400'},
{'connection', 'keep-alive'},
{'date', 'Mon, 22 Oct 2018 07:02:48 GMT'},
{'pragma', 'no-cache'},
{'via', '1.1 vegur'},
{'etag', 'W/"124-yiKdLzqO5gfBrJFrcdJ8Yq0LGnU"'},
{'server', 'cloudflare'},
{'vary', 'Origin, Accept-Encoding'},
{'content-length', '292'},
{'content-type', 'application/json; charset=utf-8'},
{'expires', 'Mon, 22 Oct 2018 11:02:48 GMT'},
{'set-cookie',
'__cfduid=de34235eb1c3436a238889924c15be9671540191768; expires=Tue, 22-Oct-19 07:02:48 GMT; path=/; domain=.typicode.com; HttpOnly'},
{'x-powered-by', 'Express'},
{'access-control-allow-credentials', 'true'},
{'x-content-type-options', 'nosniff'},
{'cf-cache-status', 'HIT'},
{'cf-ray', '46da19b6d5f87ea0-BUD'}
],
status: 200
}}
Use headers_format: :binary option to return headers as strings:
SimpleHttp.get "http://jsonplaceholder.typicode.com/posts/1", headers_format: :binary |> IO.inspect
{:ok,
%SimpleHttp.Response{
body: "{ ... }",
headers: [
{"cache-control", "public, max-age=14400"},
{"connection", "keep-alive"},
{"date", "Mon, 22 Oct 2018 07:02:48 GMT"},
...
],
status: 200
}}
GET Request with query params
{:ok, response} = SimpleHttp.get "http://jsonplaceholder.typicode.com/posts/1", [
query_params: [
postId: 1
]
]
Download a file using a GET request
{:ok, %Response{body: :saved_to_file}} = SimpleHttp.get "https://jsonplaceholder.typicode.com/posts", [
ssl: [verify: :verify_none], headers: %{"User-Agent" => "Mozilla"},
stream: "/tmp/posts.xml",
timeout: 5000
]
POST with JSON
{:ok, response} = SimpleHttp.post "http://jsonplaceholder.typicode.com/posts", [
body: "{\"name\":\"foo.example.com\"}",
headers: %{
"Content-Type" => "application/x-www-form-urlencoded",
"Authorization" => "Bearer hash",
"X-Customer" => "123"
},
timeout: 1000,
connect_timeout: 1000
]
POST with params
{:ok, response} = SimpleHttp.post "http://jsonplaceholder.typicode.com/posts", [
params: [
title: "title is present here",
message: "hello world!"
],
headers: %{
"Content-Type" => "application/x-www-form-urlencoded",
"Authorization" => "Bearer hash",
"X-Customer" => "123"
},
timeout: 1000,
connect_timeout: 1000
]
Run a request in a custom HTTP profile with custom options
{:ok, response} = SimpleHttp.get "https://jsonplaceholder.typicode.com/posts", [
ssl: [verify: :verify_none], headers: %{"User-Agent" => "Mozilla"},
timeout: 5000,
profile: :test,
verbose: :verbose
]
:ok = SimpleHttp.close(response) # Stop the HTTPC :test profile
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
