How I wrote the http-client for MRuby

April 4, 2017    ruby open-source mrbgems mruby http http-client

Hi guys. While I was working on the library for Telegram API. I ran into the problem of finding a good http-client library. Some libraries did not allow multipart/form-data requests. And in others it was necessary to form the body itself. I thought that this is a problem that I can solve. I wrote a library, which is a small http-client (less than 200 lines of code). There are still small problems in it. So I will be glad to any help.

So here is link on mruby-smallhttp.

How to Install by mrbgems

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



# GET Request"").get
#=> response

# POST Request
data = { name: 'value' }
headers = {'Content-Type' => 'application/json'}"").post(data, headers)
#=> response

# PUT Request
http ="")
http.put(data, headers)

# DELETE Request
http ="")
http.delete(data, headers)
#=> response

# HEAD & OPTIONS Request
http ="")
http.request("HEAD", body, header)
#=> response

How to send file

# How to send file in post request
body = { name: 'value', file:'filename') }
header = { 'Content-Type' => 'multipart/form-data' }
http =""), header)
#=> response

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


comments powered by Disqus