API-Axle: Tips, Tricks and Gotchas

This specific content was written 10 years ago. Please keep this in mind as it may be outdated and not adhering to best-practices.

Api-Axle

This is a brief post to help beginners with API-Axle. What is API-Axle? As described on their site:

ApiAxle is a proxy that sits on your network, in front of your API(s) and manages things that you shouldn’t have to, like rate limiting, authentication and analytics. It’s fast, open and easy to configure.

Here are some tips to help out with the initial instructions at:  http://apiaxle.com/docs/try-it-now/ .

Note: myapi in myapi.api.localhost should be replaced by your own api name.

Increase Timeout

The initial timeout (2 seconds) can result in errors because your backend API server takes time to reply to api-axle. In order to increase this you can use the endPointTimeout parameter.

Example (10 seconds):

axle> api "myapi" create endPoint="stream.site.org:80" endPointTimeout=10 
axle> key "1234" create 
axle> api myapi linkkey "1234"

Edit Local Hosts File

Api-Axle uses the host in the request URL to determine which API is requested. This is exactly the same way that vhosts work in apache.

Therefore, an easy way to do an initial test is to add the following to your local machine host file:

IPAddressOfAPIAXLE          myapi.api.localhost

Once you edit your hosts, your API will be available with the URLs:

http://myapi.api.localhost:3000/webserviceHere?api_key=1234

Install  apiaxle-api

In order to be able to run analytics and also use the full API, as defined at http://apiaxle.com/api.html , it is required to additionally  install apiaxle-api (which is not included with basic apiaxle).

Installation:

$ sudo npm install apiaxle-api
$ apiaxle-api
Execution:
$ nohup apiaxle-api -p 3001
$ curl "http://127.0.0.1:3001/v1/api/myapi/keycharts?granularity=day"

 

Configure NGinx

It is recommended to run as many apiaxle as there are cores on different ports and use nginx to specify a cluster. Nginx then recieves requests on a default port (e.g. 80), and redirects requests to apiaxle instances while also changing the host in the request to fit “myapi.api.localhost”.

 



Menelaos Bakopoulos

Mr. Menelaos Bakopoulos is currently pursuing his PhD both at Center for TeleInFrastruktur (CTiF) at Aalborg University (AAU) in Denmark and Athens Information Technology (AIT) in Athens, Greece. He received a Master in Information Technology and Telecommunications Systems from Athens Information Technology and a B.Sc. in Computer Science & Management Information Systems from the American College of Thessaloniki. Since April 2008 he has been a member of the Multimedia, Knowledge, and Web Technologies Group.

More Posts