Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Christopher Stillman
Christopher Stillman
7,304 Points

Net::HTTP Proxy

Does anyone have a novice friendly resource showing how to use Net::HTTP in Ruby/Rails to create a proxy to get around the same-origin policy?

I've spent about three weeks learning a dozen ways you can't do it and all seems to point to me needing to build a web proxy.

I would appreciate any resources or even a good learning starting point.

Just to give some background on my problem I have a site A that I can send specific URL to get back an XML page and I want to parse that response data on my site B for viewing with JavaScript.

I've had quite a hard learning curve of learning that I can't use ajax, iframes, dynamic JS tags, flash hax, jsonp, or json and that the server doesn't support CORS.

1 Answer

Christopher Stillman
Christopher Stillman
7,304 Points

I took a few months to learn, but what I figured out for my use case was to use Ruby on Rails and HTTParty gem to call the API I was pulling data from and then dump this data into a view. From there other views could parse the data with JS as needed. There is probably a more efficient way to do this but this worked for me.