• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

JuliaWeb/HTTP.jl: HTTP for Julia

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

JuliaWeb/HTTP.jl

开源软件地址:

https://github.com/JuliaWeb/HTTP.jl

开源编程语言:

Julia 99.5%

开源软件介绍:

HTTP

HTTP client and server functionality for Julia

Documentation Build Status

Installation

The package can be installed with Julia's package manager, either by using the Pkg REPL mode (press ] to enter):

pkg> add HTTP

or by using Pkg functions

julia> using Pkg; Pkg.add("HTTP")

Project Status

The package has matured and is used in many production systems. But as with all open-source software, please try it out and report your experience.

The package is tested against current Julia LTS (1.6), and 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")
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:

The server will start listening on 127.0.0.1:8081 by default.

using HTTP

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
    HTTP.setstatus(http, 404)
    HTTP.setheader(http, "Foo-Header" => "bar")
    HTTP.startwrite(http)
    write(http, "response body")
    write(http, "more response body")
end

HTTP.Handlers.serve:

using HTTP

HTTP.serve() do request::HTTP.Request
   @show request
   @show request.method
   @show HTTP.header(request, "Content-Type")
   @show request.body
   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", 8081) do ws
        for msg in ws
            send(ws, msg)
        end
    end

julia> HTTP.WebSockets.open("ws://127.0.0.1:8081") do ws
           send(ws, "Hello")
           s = receive(ws)
           println(x)
       end;
Hello



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap