• This repository has been archived on 10/Nov/2017
  • Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A streaming REST client for Ruby, using libcurl

A streaming REST client for Ruby that uses libcurl

Features

  • rest-client like API
  • Streaming API allows the caller to be handed chunks of the response while it's being received
  • uses Encoding.default_internal (otherwise falls back to utf-8) for strings it hands back in 1.9

How to install

Nothing special about it, just:

sudo gem install streamly

Example of use

A basic HEAD request

Streamly.head 'www.somehost.com'

Or streaming

Streamly.head 'www.somehost.com' do |header_chunk|
  # do something with header_chunk
end

You can also pass a Hash of headers

Streamly.head 'www.somehost.com', {"User-Agent" => "Your Mom"}

A basic GET request

Streamly.get 'www.somehost.com'

Or streaming

Streamly.get 'www.somehost.com' do |body_chunk|
  # do something with body_chunk
end

You can also pass a Hash of headers

Streamly.get 'www.somehost.com', {"User-Agent" => "Your Mom"}

A basic POST request

Streamly.post 'www.somehost.com', 'blah=foo'

Or streaming

Streamly.post 'www.somehost.com', 'blah=foo' do |body_chunk|
  # do something with body_chunk
end

You can also pass a Hash of headers

Streamly.post 'www.somehost.com', 'blah=foo', {"User-Agent" => "Your Mom"}

A basic PUT request

Streamly.put 'www.somehost.com', 'blah=foo'

Or streaming

Streamly.put 'www.somehost.com', 'blah=foo' do |body_chunk|
  # do something with body_chunk
end

You can also pass a Hash of headers

Streamly.put 'www.somehost.com', 'blah=foo', {"User-Agent" => "Your Mom"}

A basic DELETE request

Streamly.delete 'www.somehost.com'

Or streaming

Streamly.delete 'www.somehost.com' do |body_chunk|
  # do something with body_chunk
end

You can also pass a Hash of headers

Streamly.delete 'www.somehost.com', {"User-Agent" => "Your Mom"}

== Benchmarks

Fetching 2,405,005 bytes of JSON from a local lighttpd server

  • Streamly: 0.011s
  • Shell out to curl: 0.046s
  • rest-client: 0.205s

Streaming, and parsing 2,405,005 bytes of JSON from a local lighttpd server

  • Streamly: 0.231s
  • Shell out to curl: 0.341s
  • rest-client: 0.447s

Other Notes

This library was basically an exercise in dealing with libcurl in C.

Special Thanks

There are quite a few extremely nice REST client libraries out there for Ruby today. I especially owe thanks to the following projects. Without them I probably would have never had the inspiration to even take the time to write this library. In Streamly, you'll find snippets of code, API patterns and examples from all 3 of these projects. I'll do my best to make sure I give credit where it's due in the source. Please let me know if I've missed something!

And again, the Github crew for this amazing service!

More Repositories

1

mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql
Ruby
2,247
star
2

yajl-ruby

A streaming JSON parsing and encoding library for Ruby (C bindings to yajl)
C
1,478
star
3

charlock_holmes

Character encoding detection, brought to you by ICU
Ruby
1,034
star
4

escape_utils

Faster string escaping routines for your ruby apps
C
516
star
5

commit-message

A quick little macOS utility to make writing commit messages easier
Swift
45
star
6

jquery-infinite-scroll

jQuery Infinite Scroll plugin
JavaScript
43
star
7

bzip2-ruby

Original libbz2 ruby C bindings from Guy Decoux, with some new love
C
41
star
8

utf8

A lightweight UTF8-aware String class meant for use with Ruby 1.8.x
C
33
star
9

fast_xs

excessively fast escaping
Ruby
28
star
10

eventdns

An EventMachine based DNS server
Ruby
17
star
11

mochilo

A ruby library for BananaPack
C
14
star
12

http-switchboard

an http switchboard implementation that can use rev, eventmachine or regular threaded "panels"
Ruby
8
star
13

jquery-autocompleter

jQuery Autocompleter Plugin
JavaScript
8
star
14

freckle-api

A ruby client for the Freckle API
Ruby
8
star
15

powerwall-homekit

HomeKit accessory for Tesla Powerwalls
Go
7
star
16

jquery-field-validations

A half-assed port of ActiveRecord validations to jQuery
JavaScript
7
star
17

ohsnap

Ruby library for the Snappy compression algorithm
C
5
star
18

handbrake.rb

Ruby bindings to libhb
C
3
star
19

fiscal_year_calculations

Some helper methods for the Time object for fiscal year calculation
Ruby
3
star
20

json-machine

Ruby
3
star
21

wesabe-api

A ruby client for the Wesabe API
Ruby
3
star
22

dynamic_asset_helper

Rails plugin providing helpers to dynamically include JS/CSS assets based on routes
Ruby
2
star
23

banana_phone

BananaPhone is RPC for BananaPack
Ruby
2
star
24

screenlogic-homekit

A virtual HomeKit accessory for the Pentair ScreenLogic protocol adapter
Go
2
star
25

arel_profile

Ruby
1
star