# Ruby Net::HTTP vs Sketchup::Http

**URL:** <https://forums.sketchup.com/t/ruby-net-http-vs-sketchup-http/94844>\
**Category:** Ruby API\
**Created:** [May 6, 2019, 5:01pm UTC](https://forums.sketchup.com/t/ruby-net-http-vs-sketchup-http/94844 "2019-05-06T17:01:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSP\_Greg](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/msp_greg/32/206066_2.png) [@MSP\_Greg](https://forums.sketchup.com/u/MSP_Greg)\
**Post date:** [May 6, 2019, 5:01pm UTC](https://forums.sketchup.com/t/ruby-net-http-vs-sketchup-http/94844/1 "2019-05-06T17:01:12Z")

</div>

I was recently writing some (stand-alone) Ruby code that hit several servers with REST/API HTTP calls. IOW, using http to retrieve data (json) from a server.

All of it was done with the Ruby Net::HTTP library ([2.5](https://msp-greg.github.io/ruby_2_5/net-http/Net/HTTP.html), [2.2](https://msp-greg.github.io/ruby_2_2/net-http/Net/HTTP.html)) over ssl. I wrote the code using Ruby 2.7.0dev, but it works fine in SU 2018 with Ruby 2.2.4.

Back in the old days of SketchUp (SU), the Net::HTTP library had issues, and the SU team added [Sketchup::Http](https://msp-greg.github.io/su/Sketchup/Http.html) as a replacement.

I think that if one is targeting SU versions with Ruby 2.2 or later, one should consider using Net::HTTP.

Pros:

1. If one is doing multiple requests, and given that many connections are using ssl (https), using [Net:HTTP.start](https://msp-greg.github.io/ruby_2_5/net-http/Net/HTTP.html#start-class_method) allows one to negotiate a single ssl connection and perform multiple requests, assuming the conections are done in quick succession.

2. Net:HTTP.start’s options parameter allows more control over the connection.

3. Net:HTTP can be used in stand-alone Ruby, allowing one to write and test code there.

Cons:

1. Net:HTTP uses the OpenSSL library that Ruby is packaged with. OpenSSL 1.0.2 and earlier takes a second or two to intialize itself on the first connection. Subsequent connections are faster. This may not be an issue with Sketchup::Http.

Misc:

To see what version of OpenSSL is used:

```ruby
require 'openssl' ; puts OpenSSL::OPENSSL_LIBRARY_VERSION

```

---

<div class="post-metadata">

**Author:** ![eneroth3](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/eneroth3/32/1222_2.png) [@eneroth3](https://forums.sketchup.com/u/eneroth3)\
**Post date:** [May 6, 2019, 8:22pm UTC](https://forums.sketchup.com/t/ruby-net-http-vs-sketchup-http/94844/2 "2019-05-06T20:22:24Z")

</div>

Here’s a discussion about this in the API issue tracker: [What's wrong with the StdLib HTTP module · Issue #110 · SketchUp/api-issue-tracker · GitHub](https://github.com/SketchUp/api-issue-tracker/issues/110)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 7, 2019, 1:46am UTC](https://forums.sketchup.com/t/ruby-net-http-vs-sketchup-http/94844/3 "2019-05-07T01:46:05Z")

</div>

> [@MSP\_Greg](#):
>
> Back in the old days of SketchUp (SU), the Net::HTTP library had issues, and the SU team added [Sketchup::Http](https://msp-greg.github.io/su/Sketchup/Http.html) as a replacement.

The main issue is that the use of `Net::HTTP` **blocks** SketchUp. You might not notice if the server response is fast, but you will if things are slow. The SketchUp application can go into “Not Responding” mode.

Also if your extension needs to connect to a server when it loads, this can cause a noticeable delay in SketchUp’s loading and toolbar building.

The API block form methods are implemented to be non-blocking.

> [@MSP\_Greg](#):
>
> I think that if one is targeting SU versions with Ruby 2.2 or later, one should consider using Net::HTTP.

The above blocking situation is still true in all versions up through 2019, AFAIK.
