Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 3.79 KB

README.md

File metadata and controls

110 lines (80 loc) · 3.79 KB

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.listen() 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