Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gdwrd/mruby-smallhttp
mruby-smallhttp for mruby
https://github.com/gdwrd/mruby-smallhttp
http http-client mruby mruby-gem smallhtttp
Last synced: 2 months ago
JSON representation
mruby-smallhttp for mruby
- Host: GitHub
- URL: https://github.com/gdwrd/mruby-smallhttp
- Owner: gdwrd
- License: mit
- Created: 2017-04-03T11:03:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-25T09:44:29.000Z (almost 7 years ago)
- Last Synced: 2024-08-24T03:01:34.329Z (5 months ago)
- Topics: http, http-client, mruby, mruby-gem, smallhtttp
- Language: Ruby
- Homepage: https://nsheremet.pw/mruby-smallhttp
- Size: 15.6 KB
- Stars: 10
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mruby - mruby-simplehttp - Small http-client gem for mruby. (Web Frameworks)
README
# mruby-smallhttp
[![Build Status](https://travis-ci.org/nsheremet/mruby-smallhttp.svg?branch=master)](https://travis-ci.org/nsheremet/mruby-smallhttp)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````ruby
MRuby::Build.new do |conf|
conf.gem :mgem => 'mruby-smallhttp'
end
```## Example
### Requests
```ruby
# 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
```ruby
# 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