Enterprise Integration Zone is brought to you in partnership with:

Daniel Doubrovkine (aka dB.) is one of the tallest engineers at Art.sy. He founded and exited a successful Swiss start-up in the 90s, worked for Microsoft Corp. in Redmond, specializing in security and authentication, dabbled in large scale social networking and ran a big team that developed an expensive Enterprise product in NYC. After turning open-source cheerleader a few years ago in the worlds of C++, Java and .NET, he converted himself to Ruby and has been slowly unlearning everything he learned in the last 15 years of software practice. Daniel has posted 46 posts at DZone. You can read more from them at their website. View Full User Profile

Making HTTPs Requests in Ruby & JavaScript w/ Node.js

09.30.2013
| 2519 views |
  • submit to reddit

Making HTTPS requests seems oddly difficult. Why can't an HTTP library just figure things out for me like curl does? It mostly can...

Ruby

You have to breakup the URL into a host, port, and path, then make a request with use_ssl.
 

    $ irb
     
    require 'net/http'
    uri = URI::parse("https://artsy.net/api/v1/system/up")
    Net::HTTP.start uri.host, uri.port, use_ssl: (uri.scheme == "https") do |http|
      request = Net::HTTP::Get.new(uri.path)
      response = http.request request
      puts response.body
    end

Node.js

A little simpler. Superagent, also known as “ajax with less suck,” can take care of everything.

    $ npm install -g superagent
     
    $ coffee
     
    http = require('superagent')
    http.get('https://artsy.net/api/v1/system/up').end((err, res) -> console.log res.body)




Published at DZone with permission of its author, Daniel Doubrovkine. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)