Giter VIP home page Giter VIP logo

http.async.client's Introduction

http.async.client - Asynchronous HTTP Client - Clojure

http.async.client is the Asynchronous HTTP Client for Clojure. It is promise-based and uses the Asynchronous Http Client for Java for the heavy lifting.

Versioning

This library uses semantic versioning. An overview of changes by version is available in the changelog.

Distribution

All released artifacts are deployed to Clojars.

http://clojars.org/http.async.client/latest-version.svg

Build status

TravisCI is used to track the build status of intermediate commits on the following branches:

masterhttps://secure.travis-ci.org/cch1/http.async.client.png?branch=master
developmenthttps://secure.travis-ci.org/cch1/http.async.client.png?branch=development

Examples

Declare dependency (using leiningen, in this example):

(defproject your-project "1.0.0-SNAPSHOT"
  :description "Your project description"
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [http.async.client "1.2.0"]])

Asynchronous GET request

(ns async-get
  (:require [http.async.client :as http]))

(with-open [client (http/create-client)]
  (let [response (http/GET client "https://github.com/cch1/http.async.client/")]
    (-> response
        http/await
        http/string)))

WebSocket client

(ns ws-client
  (:require [http.async.client :as http]))

(def url "ws://remote-websocket-url:1337")

(defn on-open [ws]
  (println "Connected to WebSocket."))

(defn on-close [ws code reason]
  (println "Connection to WebSocket closed.\n"
           (format "[%s] %s" code reason)))

(defn on-error [ws e]
  (println "ERROR:" e))

(defn handle-message [ws msg]
  (prn "got message:" msg))

(defn -main []
  (println "Connecting...")
  (with-open [client (http/create-client)]
    (let [ws (http/websocket client
                             url
                             :open  on-open
                             :close on-close
                             :error on-error
                             :text handle-message)]
      ; this loop-recur is here as a placeholder to keep the process
      ; from ending, so that the message-handling function will continue to
      ; print messages to STDOUT until Ctrl-C is pressed
      (loop [] (recur)))))

More info

It runs with Clojure 1.5.1, 1.6.0, 1.7.0 and 1.9.0. Development is against Clojure 1.9.0.

For complete documentation refer to the project documentation index.

http.async.client is distributed under Apache License, Version 2.0.

If you would like to report an problem or submit a request, create an issue.

Finally, much thanks is owed to those contributors who have made this project so successful.

http.async.client's People

Contributors

neotyk avatar cch1 avatar pbostrom avatar adamwynne avatar thoughtmanifest avatar skuro avatar jcrossley3 avatar xeqi avatar josephwilk avatar svandegi avatar puredanger avatar timmc avatar michaelklishin avatar michaelneale avatar klang avatar jkk avatar freethejazz avatar daveyarwood avatar danieljomphe avatar bpoweski avatar

Watchers

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.