github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

gingerhendrix / json_proxy

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (3)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (3)
    • 0.6.0
    • 0.6.2
    • master ✓
  • Tags (3)
    • v0.6.1
    • v0.5.2
    • v0.5.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A json_p server for proxying web api requests. — Read more

  cancel

http://projects.gandrew.com/json_proxy/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added database method to route handler for use by service 
Gareth Andrew (author)
Sat Sep 26 11:34:17 -0700 2009
commit  51966796e3ea7564c901dfb4957536d248320b93
tree    25f81e86b94fa242ac020f813ff5354e1d8b7eb4
parent  a04458602841e77da60754dcdf13ebc026b53102
json_proxy /
name age
history
message
file .gitignore Loading commit data...
file History.txt
file PLANNING
file README.rdoc
file Rakefile
file TODO
directory bin/
directory lib/
directory tasks/
directory test/
directory website/
README.rdoc

Readme

Json Proxy is a small server/dsl intending for serving JSON documents, and in particular JSON documents created from external webservices. JsonProxy supports

  • Caching - with either CouchDb or a simple Filesystem based cache
  • Asynchronous Operation - Json Proxy supports asynchronous data loading via a HTTP polling mechanism

Prequisites

  • Couchdb (For caching, alternative FileCache exists)
  • Starling (For queue)
  • Rack (For server)

DSL

The JsonProxy DSL is used for creating new services

  np_namespace "echo" do |ns|
    ns.route 'echo', [:message] do |message|
      {:message => message}
    end
  end

Each route should return an object with a #to_json method.

Cache

All queries are cached, the cache can be controlled by setting the cache_expiry and cache_key options.

JSON Envelope

The response is always a JSON object, this object is an envelope around the data. The data can be accessed through the data property of the response, the other properties of the response are used for meta-information such as the response code and response message.

  http://localhost/echo/echo?message=blah&jsonp=callback
    => {status : 200, statusMessage : "Ok", data : {message : "blah" } }

JSON-P

If the request has an argument ‘jsonp’ the server will prefix the response with the argument value, allowing the response to be used to trigger callbacks.

  http://localhost/echo/echo?message=blah&jsonp=callback
    => callback({status : 200, statusMessage : "Ok", data : {message : "blah" } })

Asynchronous Operation

JSON Proxy supports asynchronous operation by returning immediately if the data is not in the cache. The server returns a 202 status code in this scenario. The operation is then performed in the background, while the client polls the server. Once the operation has completed the data will be available in the cache and will be sent to the client on the next request.

  Loop while status is 202
    http://localhost/echo/echo?message=blah
      => {status : 202, statusMessage : "Processing. Please retry shortly" }
  end
  http://localhost/echo/echo?message=blah
    => {status : 200, statusMessage : "Ok", data : {message : "blah" } }

Background processing is performed by using a shared queue (implemented using starling). When a cache miss occurs the server adds the current url to a queue including an extra force parameter. The QueueDaemon gets urls from the queue and fetches them. The force parameter ensures that the operation is processed synchronously.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server