Automatic Testing of REST Web Services Client with Rails

Owen Ou

@JingwenOwenOu

http://owenou.com/2011/07/20/testing-rest-web-services-with-rails.html

25 August 2011

Creative Commons License

What is REST web service?

REST == Representational State Transfer

  1. HTTP: CRUD - POST, GET, PUT, DELETE
  2. resources: anything we expose to the web, e.g., a tweet
  3. identifiers: a URI uniquely identifies a web resource, e.g., http://api.twitter.com/tweets
  4. representations: a transformation or a view of a resource’s state at an instant time, e.g., JSON

A REST web service example

# GET http://api.twitter.com/:user_id/statuses/show/:tweet_id.json

$ curl http://api.twitter.com/1/statuses/show/24858112192159745.json
{
  "created_at": "Tue Jan 11 16:00:10 +0000 2011",

  "text": "Sadly, I have not yet hit peak e-mail http://t.co/o9QIqTH",

  "id": 24858112192159745,

  ....
}

REST web services architecture

REST architecture

Why REST web services?

SOA embraces Unix.

The famous “Unix philosophy”:

Write programs that do one thing and do it well

Write programs to work together

Write programs that handle text streams, because that is a universal interface

    # a sample pipelined shell command
    $ cat `find ~/bin/ -name "\*.sh"` | sed -e '/\^ \*#/d' | wc -l

replace “programs” with “services” => SOA

Why REST web services?

Pros:

Example: Google Accounts (SSO), Amazon Web Services API, Twitter’s API, etc.

Why not REST web services?

Cons:

Challenges of testing REST web services client

Let’s build and test a REST web service for Twitter+, shall we?

Twitter+ architecture

Twitter+ architecture

Twitter+ TODO

Other usages

Summary

Reference

Questions?