rainbows for 3rd party api

Eric Wong normalperson at yhbt.net
Thu Nov 5 18:06:39 EST 2009

Giovanni Lion <giovanni.lion at gmail.com> wrote:
> > Hi Giovanni,
> >
> > 3rd party API responses are exactly one of the uses Rainbows! was built
> > for.
> >
> > You really only want DevFdResponse if you're doing a straight proxy
> > between the 3rd party and your client without modifying the data.  Since
> > you seem to be getting XML and rendering HTML, you probably can't use
> > DevFdResponse efficiently.  Don't despair, though, Rainbows! still
> > gives you plenty of options :)
> >
> > You can build a Rack config.ru to use with Rails, too. In fact, you'll
> > have to for now since we're unsure if we want to support a
> > "rainbows_rails" wrapper like I do with "unicorn_rails".  Using
> > config.ru gives you much more flexibility to route around/outside
> > of Rails.
> Ok i think i got most of it. Now i was just thinking about the best
> way to get this going. The issue now is that processing the xml into
> the html is something I prefer keeping insde the app for consistency.
> My idea was to do something like this, i use an example this time:
> 1) I get a request for a friend list html partial
> 2) I intercept it and using revactor
> 3) Wait for the response (It shouldn't be called waiting with revactor
> and fibers, right?)

Well, from the caller's point of view, it is waiting :)

> 4) I write the response to memcached
> 5) I call the rails app who now fetches from cache the friend list
> 6) The rails app renders the partial and everybody is happy
> Do you think this is a good flow? Should I create a specific method instead?

Depends on the rest of your app, I guess.  Is your Rails app
reentrant?  If so, definitely go for it.  If you're dealing
with DB connections in there, compatibility will probably be
better with the ThreadPool or ThreadSpawn models unless somebody
writes Revactor-enabled DB libraries.

> Also, another issue is not clear to me yet. I need to make api
> requests with oauth, hence there is a logic layer on top of the http
> request. I would probably need to brake it down and replace Net:HTTP
> with Revactor::HttpClient, am i correct?

Yes.  To effectively use Revactor you pretty much have to change any
parts of your app/libraries to use Revactor's networking API.
Fortunately it's not too hard since program logic is still linear with
the Actor model.

You might even want to do it for memcached, too, but then again
memcached is pretty fast on a LAN and you might not notice it block.

Eric Wong

More information about the rainbows-talk mailing list