Soapi.js defines Route
'classes' for each and every route, or urlURL, in the StackOverflowStack Overflow API.
A Route
is primarily a 'class' off of which to hang the urlURL path and define the parameters for the urlURL. Specifying required 'id' parameters in the factory method call and the application of parameters via explicitly defined parameter objects or jsonJSON literals will be covered later in this post.
success
(required) -function(data)
-data
will be a JavaScript object (jsob) built from the response jsonJSON as defined on the route's help-page.error
(optional) -function(err)
-err
will be a jsob shaped like this:{ code: number , message: "String", urlURL: "String"}
timeout
(optional) -number
- The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.
success
(required) -function(data)
-data
will be a JavaScript object (jsob) built from the response jsonJSON as defined on the route's help-page.error
(optional) -function(err)
-err
will be a jsob shaped like this:{ code: number , message: "String", urlURL: "String"}
pageCallback
(optional) -function(data)
-data
will be a JavaScript object (jsob) built from the response jsonJSON as defined on the route's help-page. You may examine this object to determine if you would like to terminate the paged request. Simply returntrue
if you wish to terminate and receive the current aggregated results in yoursuccess
function.timeout
(optional) -number
- The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.
resulting in a urlURL resembling the following (urlURL-encoded, of course):
The other parameters of the route may be supplied as an object literal in the factory method, as shown, explicitly set on the Route
object itself or appiedapplied via the Route.applyParameters
function with an object literal.
asyncTest("AnswersByIdSanityCheck", function() {
expect(1);
var factory = Soapi.RouteFactory('api.stackoverflow.com', apiKey);
var route = factory.AnswersById(2917525, 2701766, {
//id is set in factory method call
// these are default values that do not result in a
// parameter being added to the urlURL
body: false,
comments: false,
sort: "",
order: "",
min: 0,
max: 0,
fromdate: 0,
todate: 0,
page: 0,
pagesize: 0
});
route.getResponse(
function (data) {
ok(data.items.length==2, 'async call succeeded, count inaccurate');
start();
},
function(err) {
ok(err.message);
start();
}, 5000);
Next: Complete Route Listing - suprisinglysurprisingly simple mastery of the API via Soapi.js lies here