By on March 30, 2012

Mashape Updates #9 – Added Erlang Clients

Mashape updates

Stormtroopers working on Mashape updates
Image credit:

Mashape now auto-generates Erlang clients for all APIs!

Similar to other supported languages, the clients provide both synchronous and asynchronous requests. For the Erlang clients, you can provide either a function to be run on completion of the request or a Pid for a process that will send the result of the request upon completion.

Downloading a client comes with all the necessary Erlang dependencies to get started – ibrowsemochiweb, as well as the Mashape Erlang application emashape which is the core common functionality between all Erlang Mashape clients. They also come with both a sinan and rebar config for easy use with either Erlang build tool.

Let’s look at an example of the client in action. We’ll use the Chatterbox API for this example.

setup(PublicKey, PrivateKey) ->
classifytext(Lang, Text) ->
classifytext(Lang, Text, Optional) when is_list(Optional) ->
classifytext(Lang, Text, Callback) ->
classifytext(Lang, Text, Optional, Callback) ->

The setup/2 function takes your Mashape public and private key, starts required dependencies and creates a new process for handling required state for making requests. For this client, we have only one endpoint to make requests to, but multiple definitions. The classifytext function can be as simple as the first definition, where you provide only the language of the text and the text itself, and returns the classification. The other three allows for optional paramters, a callback or both. Optional parameters for the request must be passed as a proplist. In this case the only optional parameter is ‘exclude’, so it would look like: [{“exclude”, “value”}].

You can get the core application, emashape, on github:

Installing the Mashape application to your lib directory simplifies the use of the clients. You can install it by copying lib/emashape-* and the contents of deps/ to the lib of your Erlang install, example /usr/local/erlang/lib/.