Created
June 12, 2014 07:34
-
-
Save polarblau/44a67e2eff325f762068 to your computer and use it in GitHub Desktop.
Proxy API requests through e.g. your Middleman to avoid cross domain issues.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class APIProxy | |
def call(env) | |
request = Rack::Request.new(env) | |
api_url = request.params['api_url'] | |
[200, { 'Content-Type' => 'application/json' }, [get_json(api_url)]] | |
end | |
private | |
def get_json(url) | |
uri = URI.parse(URI::unescape(url)) | |
response = Net::HTTP.get(uri) | |
response | |
end | |
end | |
map '/api_proxy' do | |
run APIProxy.new | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment