Basic Requests
Reference Implementations
JavaScript
var key = 'YOUR_KEY';
var request = {
api: 'citydriving/profile/get',
params: {
key: key,
username: 'USERNAME'
}
};
TCAPIRequest(request, function(data) {
// Do something with the returned data
console.log(data);
});
function TCAPIRequest(req, callback) {
this.baseUrl = 'https://api.tc-gaming.co.uk/';
this.xhr = new XMLHttpRequest();
this.qs = "";
if(Object.keys(req.params).length > 0) {
for(var param in req.params) {
this.qs.length == 0 ? (qs += "?") : (qs += "&");
this.qs += param + '=' + req.params[param];
}
}
this.url = this.baseUrl + req.api + this.qs;
this.xhr.onreadystatechange = function() {
if(this.xhr.readyState === XMLHttpRequest.DONE) {
if(this.xhr.status === 200) callback(JSON.parse(this.xhr.response));
}
}.bind(this);
this.xhr.open('GET', this.url);
this.xhr.send();
}JavaScript (JQuery)
Last updated
Was this helpful?