Code Monkey home page Code Monkey logo

http.jl's Introduction

HTTP

HTTP client and server functionality for Julia

Documentation PackageEvaluator Build Status

Installation

The package is registered in METADATA.jl and so can be installed with Pkg.add.

julia> Pkg.add("HTTP")

Project Status

The package is new and not yet tested in production systems. Please try it out and report your experience.

The package is tested against Julia 0.6.2 & current master on Linux, macOS, and Windows.

Contributing and Questions

Contributions are very welcome, as are feature requests and suggestions. Please open an issue if you encounter any problems or would just like to ask a question.

Client Examples

HTTP.request sends a HTTP Request Message and returns a Response Message.

r = HTTP.request("GET", "http://httpbin.org/ip"; verbose=3)
println(r.status)
println(String(r.body))

HTTP.open sends a HTTP Request Message and opens an IO stream from which the Response can be read.

HTTP.open("GET", "https://tinyurl.com/bach-cello-suite-1-ogg") do http
    open(`vlc -q --play-and-exit --intf dummy -`, "w") do vlc
        write(vlc, http)
    end
end

Server Examples

HTTP.Servers.listen:

HTTP.listen() do http::HTTP.Stream
    @show http.message
    @show HTTP.header(http, "Content-Type")
    while !eof(http)
        println("body data: ", String(readavailable(http)))
    end
    setstatus(http, 404)
    setheader(http, "Foo-Header" => "bar")
    startwrite(http)
    write(http, "response body")
    write(http, "more response body")
end

HTTP.Handlers.serve:

HTTP.serve() do request::HTTP.Request
   @show request
   @show request.method
   @show HTTP.header(request, "Content-Type")
   @show HTTP.payload(request)
   try
       return HTTP.Response("Hello")
   catch e
       return HTTP.Response(404, "Error: $e")
   end
end

WebSocket Examples

julia> @async HTTP.WebSockets.listen("127.0.0.1", UInt16(8081)) do ws
           while !eof(ws)
               data = readavailable(ws)
               write(ws, data)
           end
       end

julia> HTTP.WebSockets.open("ws://127.0.0.1:8081") do ws
           write(ws, "Hello")
           x = readavailable(ws)
           @show x
           println(String(x))
       end;
x = UInt8[0x48, 0x65, 0x6c, 0x6c, 0x6f]
Hello

http.jl's People

Contributors

ararslan avatar astrieanna avatar carpenecopinum avatar catawbasam avatar christopher-dg avatar chuckha avatar despeset avatar dirk avatar ericforgy avatar erikedin avatar garborg avatar iainnz avatar iamed2 avatar jiahao avatar keno avatar malmaud avatar mlubin avatar oxinabox avatar quinnj avatar racycle avatar ranjanan avatar rened avatar samoconnor avatar stefankarpinski avatar tanmaykm avatar tkelman avatar westleyargentum avatar wildart avatar yuyichao avatar zachallaun avatar

Watchers

 avatar  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.