Skip to content

Asmod4n/mruby-httpsclient

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

mruby-httpsclient

Prerequirements

You need mruby-tls which needs libressl (http://www.libressl.org) somewhere your compiler can find it, for example on OS X with homebrew you have to add something like this to build_config.rb

  conf.gem mgem: 'mruby-tls' do |g|
    g.cc.include_paths << '/usr/local/opt/libressl/include'
    g.linker.library_paths << '/usr/local/opt/libressl/lib'
  end

Example

Simple GET

HttpsClient.new.get("https://github.com/") do |response|
  unless response.body
    puts response.minor_version
    puts response.status
    puts response.msg
    puts response.headers
  else
    print response.body
  end
end

Simple POST

body = "hello world"
HttpsClient.new.post("https://github.com", body) do |response|
  unless response.body
    puts response.minor_version
    puts response.status
    puts response.msg
    puts response.headers
  else
    print response.body
  end
end

POST a Enumerable

body = ["hello", "world"]
HttpsClient.new.post("https://github.com", body) do |response|
  unless response.body
    puts response.minor_version
    puts response.status
    puts response.msg
    puts response.headers
  else
    print response.body
  end
end

POST a Fiber

body = Fiber.new do
  Fiber.yield "hello"
  Fiber.yield "world"
end
HttpsClient.new.post("https://github.com", body) do |response|
  unless response.body
    puts response.minor_version
    puts response.status
    puts response.msg
    puts response.headers
  else
    print response.body
  end
end

The response body is always streamed, if you need to work with the complete body at once you have to stitch it together.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages