Stream Paginated APIs in Elixir

_This article was recently featured in Elixir Radar. Since it was written, I’ve found a simpler way to implement this kind of Stream. I’ll be writing an updated tutorial in the future, but if you’re interested, you should also check out the current state of ExTwilio.ResultStream._

This past week, as I worked on my new ExTwilio API library for Twilio, I ran into a snag dealing with Twilio’s API pagination.

Twilio paginates its “list” APIs, requiring multiple requests to fetch all of a given resource. However, users of my API library will expect to be able to fetch all of a resource and perform operations on it, like this:

calls = ExTwilio.Call.all
Enum.each calls, fn(call) ->
  # perform some operation
end

Users won’t want to mess with the details of pagination. They want to get a collection containing everything and then operate on it.

I find that there are two basic ways to achieve this, a blocking way and a non-blocking way.

[Read More]

ExTwiml

At LeadSimple, we use Twilio to handle phone call routing. Twilio interacts with regular HTTP endpoints on your server to control calls and SMS messages, through a form of XML they call TwiML.

I’ve been toying recently ideas on how to bring next-generation Erlang (Elixir) and next-generation telephony (Twilio) together. Toward that end, I made a little library this week to make generating TwiML from Elixir easy.

[Read More]