Giter Site home page Giter Site logo

httpoison's Introduction

HTTPoison Build Status

HTTP client for Elixir, based on HTTPotion

But... why something so similar to HTTPotion?

HTTPoison uses hackney to execute HTTP requests instead of ibrowse. I like hackney ๐Ÿ‘

Using hackney we work only with binaries instead of string lists.

Usage

iex> HTTPoison.start
:ok
iex> HTTPoison.get "http://localhost:4000"
HTTPoison.Response[body: "...", headers: [{"Connection","Keep-Alive"}...], status_code: 200]
iex> HTTPoison.get "http://localhost:1"
** (HTTPoison.HTTPError) econnrefused

You can also extend it to make cool API clients or something (this example uses jsex for JSON):

defmodule GitHub do
  use HTTPoison.Base
  def process_url(url) do
    "https://api.github.com/" <> url
  end
  def process_response_body(body) do
    json = JSEX.decode! body
    json = Enum.map json, fn ({k, v}) -> { binary_to_atom(k), v } end
    json
  end
end

iex> GitHub.start
iex> GitHub.get("users/myfreeweb").body[:public_repos]
37

And now with async!

iex> HTTPoison.get "http://floatboth.com", [], [stream_to: self]
HTTPoison.AsyncResponse[id: #Reference<0.0.0.608>]
iex> flush
HTTPoison.AsyncStatus[id: #Reference<0.0.0.608>, code: 200]
HTTPoison.AsyncHeaders[id: #Reference<0.0.0.608>,
 headers: [{"Server", "cloudflare-nginx"}, {"Date", "Sun, 29 Dec 2013 17:54:24 GMT"}, {"Content-Type", "text/html; charset=utf-8"}, {"Transfer-Encoding", "chunked"}, {"Connection", "keep-alive"},
  {"Set-Cookie", "__cfduid=d845959e83669e83df85ce135a9585c031388339664499; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.floatboth.com; HttpOnly"}, {"CF-RAY", "e485af71dfd0326"}]]
HTTPoison.AsyncChunk[id: #Reference<0.0.0.608>,
 chunk: "<!DOCTYPE html>..."]
HTTPoison.AsyncChunk[id: #Reference<0.0.0.608>,
 chunk: "curity, typography..."]
HTTPoison.AsyncEnd[id: #Reference<0.0.0.608>]

License

Copyright ยฉ 2013 Eduardo Gurgel [email protected] This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details.

httpoison's People

Contributors

edgurgel avatar reset avatar

Watchers

Devin Alexander Torres avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.