Permalink
Browse files

content-type will differ based on JSON vs JSONP. added content to REA…

…DME.
  • Loading branch information...
1 parent eb9e557 commit 29ae342931fb46692c71b15438906a481a044190 Dhruv Bansal committed Sep 5, 2012
Showing with 31 additions and 5 deletions.
  1. +28 −0 README.rdoc
  2. +3 −5 innovation_matcher.rb
View
@@ -119,3 +119,31 @@ Example:
...
]
}
+
+== JSONP & Callbacks
+
+All URLs will accept the +callback+ parameter to wrap the JSON
+response in a JavaScript callback suitable for JSON-P.
+
+Example:
+
+ $ curl -s -X GET http://localhost:4567/matches/6b73f010-d469-012f-ad21-002219342852?callback=hello
+ hello({
+ "match_id": "6b73f010-d469-012f-ad21-002219342852",
+ "innovations": [
+ {
+ "id": "280",
+ "type": "Automotive",
+ "name": "internal combustion engine",
+ "photo": "http://www.flickr.com/photos/ell-r-brown/6050366599/",
+ "innovator_name": "NICOLAUS OTTO",
+ "innovation_date": "8/14/1877",
+ ...
+ "fb_user": "Dhruv Bansal"
+ },
+ { ... },
+ ...
+ ]
+ })
+
+
View
@@ -66,19 +66,17 @@ def retrieve_match uuid
end
def pretty_json obj
+
output = obj.to_json
if params['callback']
+ content_type "application/javascript"
[params['callback'], '(', output, ")\n"].join('')
else
+ content_type "application/json"
output + "\n"
end
end
-
-before do
- content_type "application/json"
-end
-
get "/matches" do
begin
user_data = JSON.parse(request.body.read)

0 comments on commit 29ae342

Please sign in to comment.