https://github.com/asmod4n/mruby-httpsclient
https://github.com/asmod4n/mruby-httpsclient
http-client mruby
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/asmod4n/mruby-httpsclient
- Owner: Asmod4n
- License: apache-2.0
- Created: 2015-01-13T05:54:46.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-04-15T16:25:54.000Z (over 8 years ago)
- Last Synced: 2025-04-07T03:34:39.359Z (9 months ago)
- Topics: http-client, mruby
- Language: Ruby
- Size: 29.3 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```ruby
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
```ruby
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
```ruby
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
```ruby
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
```ruby
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.