I am writing an API to access resources on one of my servers. Part of this API will make HTTP requests. In the name of good software design, I don't want my API to be blocking.
I am fairly new to Ruby, but in Java I would provide an Asynchronous API that returns Futures of the response. In JavaScript I would take callbacks in my methods.
I've searched for other Stack Overflow questions, and https://github.com/eventmachine/em-http-request seems to do what I want. However, I am hesitant to rely on a third-party library. Is there a Ruby native way to solve this problem, or do most developers rely on third-party libraries?
Based on my tests, MRI does support nonblocking HTTP requests simply by using a thread. Threads don't always allow parallelism in Ruby due to the GIL, but
net/http
appears to be one of the exceptions: