##Soapi.JS Usage Introduction
Soapi.JS Usage Introduction
To use Soapi.JS, simply include soapi.js
in your document.
e.g.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="scripts/Soapi.js" type="text/javascript"></script>
<!-- the rest of your document -->
Soapi.JS is designed to be very simple to use. The only 'class' you will instantiate is RouteFactory
.
RouteFactory
The RouteFactory
requires 2 parameters:
targetSite
(Required) - the full name of the API you wish to query. e.g.api.stackoverflow.com
orhttp://api.stackoverflow.com
apiKey
(Optional) - your application's registered apiKey. If you have no api key, API queries will be limited to 300 (or the latest limit) and requests will fail upon usage of that threshold. The JSONP mechanism provides no ability to access response headers and subsequently the x-rate-limit headers that provide usage metrics, so you will simply need to watch for timeouts and respond accordingly.
RouteFactory
's raison d'être is to hold a reference to the target site and the api key and build Route
objects via factory methods. NOTE: you do not have to, although you may, use the new
keyword when instantiating a RouteFactory
.
Soapi.RouteFactory('api.stackapps.com', 'api key if you gots one')
.UsersById(14)
.getResponse(function(data) {
alert(data.items[0].display_name);
});