Give any SQL database a REST interface with Sandman #

Let’s say you have a SQL database. You might wish it had a REST interface and a nice admin UI. That used to mean writing a bunch of code but now with Sandman it’s a one liner.

Zero boilerplate code is required. In fact, using sandmanctl, no code is required at all. Your existing database structure and schema is introspected and your database tables magically get a RESTful API and admin interface.

Sandman was created by Jeff Knupp and can be used with any database that SQLAlchemy supports.

Write Ruby API’s with Stripe’s Poncho (a DSL for REST interfaces) #

As we said in a previous post: WE LOVE STRIPE!

The team at Stripe has open sourced a RubyGem that makes REST API’s easy to create, Poncho. It’s compatible with any rack-based framework — like Rails or Sinatra. Best of all, it has a slew of (simple to use) features:

Installation is simple, just install the poncho gem (or add gem poncho to your Gemfile). After installation, you can setup your API:

class ChargeResource < Poncho::Resource
  param :amount, :type => :integer
end

class ChargeCreateMethod < Poncho::JSONMethod
  param :amount, :type => :integer, :required => true

  def invoke
    charge = Charge.new
    charge.amount = param(:amount)
    charge.save

    ChargeResource.new(charge)
  end
end

post '/charges', &ChargeCreateMethod

The above code, which was pulled from the documentation is using Sinatra, but you could easily swap Rails out:

match '/charges' => ChargeCreateMethod, :via => :post

The documentation is thorough, and does a great job at explaining how to use Poncho. You can also view the source or discuss this on HackerNews.

RestSharp: Simple REST and HTTP API Client for .NET #

I’m a big fan of making idiomatic language bindings for APIs. Making common tasks such as URI generation, transport, authentication, and payload parsing configurable options and providing a higher-level API lets application developers focus on the business domain instead of low-level networking.

.NET developers looking to write API wrappers without starting from
scratch should check out RestSharp from John Sheehan. Similar to Ruby’s HTTParty and others, RestSharp provides a number of features to make writing wrappers for REST web services a snap, including:

  • Automatic XML and JSON parsing including Fuzzy element name matching (“product_id” in XML/JSON will match C# property named ‘ProductId’)
  • Support for GET, POST, PUT, HEAD, OPTIONS, DELETE
  • oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authentication
  • Multi-part form/file uploads
  • Custom serialization and deserialization via ISerializer and
    IDeserializer
  • Both sync and async requests

Example

Here’s a quick example of making a simple request for XML from an API using Basic Auth:

var client = new RestClient();
client.BaseUrl = "http://twitter.com";
client.Authenticator = new HttpBasicAuthenticator("username", "password");

var request = new RestRequest();
request.Resource = "statuses/friends_timeline.xml";

RestResponse response = client.Execute(request);

In addition to using the built-in Authenticators,
you’re free to create your own:

var client = new RestClient("http://example.com");
client.Authenticator = new SimpleAuthenticator("username", "foo", "password", "bar");

var request = new RestRequest("resource", Method.GET);
client.Execute(request);

Perhaps most impressive is RestSharp’s support for a number of environments including .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, and MonoTouch. Be sure and check out the project readme for advanced usage and tips on contributing.

[Source on GitHub]

resty: Piping hot REST client for bash or zsh #

I love REST APIs, so I’m always looking for new tools for the toolbox. Resty from Micha Niskin caught my eye because it can be loaded into your bash or zsh. To install, just download the script and source it.

$ curl http://github.com/micha/resty/raw/master/resty > resty
$ . resty

Now your shell is loaded up with the Resty commands. First, set an API endpoint, like GitHub:

$ resty http://github.com
http://github.com*

Now we can make any normal GET, POST, PUT, or DELETE as you would expect.

GET /pengwynn.json

For formatted output, pipe it to pretty print:

GET /pengwynn.json | pp

… or save to a file

GET /pengwynn.json > me.json

REST on the Couch

Resty is perfect for CouchDB. Just set your endpoint

resty http://127.0.0.1:5984

… and you’re ready to create datbases

PUT /test '{}'

… and stash documents.

PUT /test/me < me.json

cURL-ing

Since Resty sits on top cURL, any additional options after the required path will be passed along to cURL:

resty http://github.com/api/v2/json
GET /repos/show/pengwynn -u pengwynn:0U812

Be sure to check out Jan-Piet Mens’ introductory screencast or the README for advanced usage.

[Source on GitHub] [Screencast]

#14: Andy Gross and Sean Cribbs on Riak

Adam and Wynn caught up with Andy Gross from Basho and Sean Cribbs, a freelance Ruby developer, to discuss Riak, the new Erlang-based NoSQL store and Ripple, Sean’s new Ruby wrapper for Riak. Items mentioned in the show: Ripple New Ruby wrapper for Riak Link walking in Riak RadiantCMS Ruby-powered Content Management System

cradle – A high-level, caching, CouchDB client for Node.js #

Intended to be a higher-level API on top of Couch, cradle from Alexis Sellier tries to bridge what’s best about CouchDB and Node.js. Cradle comes with built-in write-through caching to boost speed and easier updates and deletes.

Most methods from CouchDB map one-to-one with Cradle although some like save can orchestrate multiple operations.

From the README

var cradle = require('cradle');
var db = new(cradle.Connection).database('starwars');

db.get('vador').addCallback(function (doc) {
    doc.name; // 'Darth Vador'
    assert.equal(doc.force, 'dark');
});

db.save('skywalker', {
    force: 'light',
    name: 'Luke Skywalker'
}).addCallback(function (res) {
    // Handle success
}).addErrback(function (res) {
    // Handle error
});

[Source on GitHub] [Follow Alexis Sellier on Twitter]

riak – high performance document store built on JSON and REST #

riak
Riak, REE-ahk, combines the power of Erlang with the ubiquity of JSON to deliver a highly scalable document store over REST. Hold on CouchDB fans, before you pounce, you haven’t heard this one before.

Master-less replication

Riak is architected for master-less replication from the GET-go. All nodes participate equally in the replication so scaling horizontally means just adding new servers to join the party.

Links for powerful object graphs

Riak supports link-walking which is far more powerful than traditional relational DB joins. As Sean Cribbs explains:

Every datum stored in Riak can have one-way relationships to other data via the Link HTTP header. In the canonical example, you know the key of a band that you have stored in the “artists” bucket (Riak buckets are like database tables or S3 buckets). If that artist is linked to its albums, which are in turn linked to the tracks on the albums, you can find all of the tracks produced in a single request. As I’ll describe in the next section, this is much less painful than a JOIN in SQL because each item is operated on independently, rather than a table at a time. Here’s what that query would look like:

GET /raw/artists/TheBeatles/albums,_,_/tracks,_,1

More powerful Map/Reduce

Map/Reduce works a bit differently in Riak. Riak’s Map function expects a list of keys on which it should run. You can of course pass every key in your bucket, but doing Map in this way allows Map to be run on the node where the data is actually stored.

Riak ships with libraries for Python, Ruby, Java, Erlang, and even JavaScript. Want to know more? Stay tuned. Riak will be the focus of an upcoming episode of The Changelog.

[Source on BitBucket] [Homepage] [Brian Fink’s NYC-NoSQL talk]

neo4jr-social: REST interface for Neo4j #

Need to talk to Neo4j, the popular Java NoSQL database but no habla Java? No worries, @mdeiters has your back with Neo4jr-Social:

Neo4jr-Social is a self contained HTTP REST + JSON interface to the graph database Neo4j. Neo4jr-Social supports simple dynamic node creation, building relationships between nodes and also includes a few common social networking queries out of the box (i.e. linkedin degrees of seperation and facebook friend suggestion) with more to come.

[Source on GitHub] [API docs]