Skip to content
mruby-smallhttp for mruby
Ruby C
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
mrblib
src
test
.travis.yml
.travis_build_config.rb
LICENSE
README.md
_config.yml
mrbgem.rake
mruby-smallhttp.gem

README.md

mruby-smallhttp

Build Status

mruby-smallhttp for mruby

install by mrbgems

mruby-smallhttp it's small http lib for MRuby

Install by mrbgems

  • add conf.gem line to build_config.rb
MRuby::Build.new do |conf|
  conf.gem :mgem => 'mruby-smallhttp'
end

Example

Requests

# GET Request
HTTP.new("https://example.com/api/v1/users").get
#=> response

# POST Request
data = { name: 'value' }
headers = {'Content-Type' => 'application/json'}

HTTP.new("https://example.com/api/v1/users").post(data, headers)
#=> response

# PUT Request
http = HTTP.new("https://example.com/api/v1/users/1")
http.put(data, headers)

# DELETE Request
http = HTTP.new("https://example.com/api/v1/users/1")
http.delete(data, headers)
#=> response

# HEAD & OPTIONS Request
http = HTTP.new("https://example.com/api/v1/users/1")
http.request("HEAD", body, header)
#=> response

How to send file

# How to send file in post request
body = { name: 'value', file: File.read('filename') }
header = { 'Content-Type' => 'multipart/form-data' }
http = HTTP.new("https://example.com/api/v1/users/1")
http.post(body, header)
#=> response

Content-Type supported: application/json, application/x-www-form-urlencoded, multipart/form-data and text/plain

License

under the MIT License:

  • see LICENSE file
You can’t perform that action at this time.