Skip to content

Instantly share code, notes, and snippets.

@polarblau
Created June 12, 2014 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polarblau/44a67e2eff325f762068 to your computer and use it in GitHub Desktop.
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.
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