Coder Social home page Coder Social logo

gandolfini's Introduction

Quick start

git clone [email protected]:rcs/gandolfini.git
cd gandolfini
npm install
bin/gandolfini

What it is

James Gandolfini An homage to the most famous bouncer of all time.

Single page apps are cool. Browser security models are cool.

Developing against web APIs that don't implement CORS headers isn't cool.

We can fix that now.

Gandolfini serves as a bouncer for all those APIs that you want to use but can't. Request through Gandolfini, and get your data with all the necessary bits to let you access it on the client.

Example

Let's say we wanted to display Crunchbase data on our website, being the good web 2.3 citizens we are.

They have a nice, simple api. We'll grab the facebook info.

jQuery.get(
  'http://api.crunchbase.com/v/1/company/facebook.js',
  function(data) {
    Object.keys(data);
  },"json");

And we reload the page and load the console, already feeling our Klout score rising.

Instead of our juicy facebook data, we get:

XMLHttpRequest cannot load http://api.crunchbase.com/v/1/company/facebook.js. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

Lame. Let's route it through gandolfini.

jQuery.get('http://localhost:8080/api.crunchbase.com/v/1/company/facebook.js', function()

And now we've got what we want.

// XHR finished loading: "http://localhost:8080/api.crunchbase.com/v/1/company/facebook.js". jquery.min.js:4
["name", "permalink", "crunchbase_url", "homepage_url", "blog_url", "blog_feed_url", "twitter_username", "category_code", "number_of_employees", "founded_year", "founded_month", "founded_day", "deadpooled_year", "deadpooled_month", "deadpooled_day", "deadpooled_url", "tag_list", "alias_list", "email_address", "phone_number", "description", "created_at", "updated_at", "overview", "image", "products", "relationships", "competitions", "providerships", "total_money_raised", "funding_rounds", "investments", "acquisition", "acquisitions", "offices", "milestones", "ipo", "video_embeds", "screenshots", "external_links"]

Special sauce

Gandolfini supports special query parameters to set headers on the outgoing request.

parameter effect
_gr _gr=site.com becomes Referer: site.com
_gct _gct=application/json becomes Content-Type: application/json
_ga _ga=application/json becomes Accept: application/json

Use in an existing app

Gandolfini can also be used as Connect middleware.

http = require 'http'
connect = require 'connect'
gandolfini = require 'gandolfini'

http.createServer(
  connect()
    .use(connect.logger())
    .use(gandolfini.full())
  )
).listen(8080);

gandolfini's People

Contributors

rcs avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.