###ApiContext
Query based Soapi.JS2 usage is rooted on the ApiContext
object. This object maintains the list of Site that are available for query and provides central services.
You gotta have one and it must be initialized.
var context = new Soapi.ApiContext(apiKey);
context.initialize(function onSuccess(){
// proceed
}, function onFailed(error){
// handle error;
});
Once you have an intialized context, all query based activity will be rooted on a Site.
The ApiContext
provides access to all Stack Exchange sites via the .context.find(apiendpoint)
method which will return a Site
object.
var site = context.find("api.stackapps.com");
The official
sites, e.g. those not living in Area51, also have a convenience accessor, context.official.xxxx
.
var site = context.official.stackOverflow;
Living on the Site object are the properties you would expect, with reference to the data structure returned by /sites
, as well as query methods that provide full coverage of the Stack Exchange API.
NEXT: API Query CoverageAPI Query Coverage