GET requests
To use a GET request, you need to:
-
Add an Authorisation Header with your access token
- To get an access token, see the Login page.
- optional: Add the "accept: application/json" header
- Fill in any parameters in the URI (as indicated by the {}. The API help page of the GET request will explain the values of the parameters
- Make a web-request to the API
GET Formats
jQuery [Javascript]
Sample:
$.ajax(
{
url: 'https://api.qe.co.za/[The URI that you have built]',
headers:
{
"Authorization": "Bearer " + [Your Access Token], "accept": "*/*"
},
method: 'GET',
dataType: "json",
crossDomain: true,
xhrFields:{withCredentials: true},
success: function (data)
{
//Handle API Call Success [Note: this does not mean that the action was successful, only that the server communication was successful.]
},
error: function (xhr, error, msg)
{
//Handle AJAX Error
}
});
C#.NET
Sample:
RestClient client = new RestClient("https://api.qe.co.za/[The URI you have built]");
RestRequest request = new RestRequest();
request.Method = Method.GET;
request.AddHeader("Authorization",$"Bearer {Your Access Token}");
IRestResponse rest = client.Execute(request);
if (rest.StatusCode == HttpStatusCode.OK)
{
//Handle API Call Success [Note: this does not mean that the action was successful, only that the server communication was successful.]
//Data is in rest.Content
//If you have created a matching ResultModel<T> (if the API Call returns it). EG: ResultModel<QuoteSection> And you have included the NewtonsoftJson package in your project, you can do this.
ResultModel<T> result = JsonConvert.DeserializeObject<ResultModel<T>>(rest.Content);
}
else
{
//Handle AJAX Error
}
Flutter.Dart
Sample: [Note: This example assumes that you are using null safety in your Flutter.Dart project]
import 'package:http/http.dart' as http;
import 'dart:convert';
class ApiResult
{
String? status;
String? message;
int? identity;
int? total;
Map<String,dynamic>? result;
ApiResult({
this.status,
this.message,
this.identity,
this.total,
this.result,
});
factory ApiResult.fromJson(Map<String,dynamic> parsedJson){
return _ApiResult(
status: parsedJson['status'],
message: parsedJson['message'],
identity: parsedJson['identity']?.toInt() ?? 0,
total: parsedJson['total']?.toInt() ?? 0,
result: parsedJson['result'],
);
}
}
//Note: You should be using the DART version of the API call if it exists
//Note: This will throw an exeption on transmission error.
final response = await http.get(
Uri.https('https://api.qe.co.za','[The URI you have built]').
headers:
{
'Authorization': 'Bearer '+[Your Access Token],
'accept':'*/*'
});
//The result is in response.body
dynamic jsonData = json.decode(response.body);
ApiResult? result = ApiResult.fromJson(jsonData);
if (result.status == "ok")
{
//Handle API Call Action Success
}
else
{
//Handle API Call Action failure
throw(result.message??"Unknown API Action Error");
}
POST requests
To use a POST request, you need to:
-
Add an Authorisation Header with your access token
- To get an access token, see the Login page.
- Fill in any body parameters. The API help page of the POST request will explain the values of the parameters
- Make a web-request to the API
jQuery [Javascript]
Sample:
$.ajax(
{
url: 'https://api.qe.co.za/[The URI that you have built]',
headers:
{
"Authorization": "Bearer " + [Your Access Token], "accept": "*/*"
},
method: 'POST',
dataType: "json",
data:
{
'body string parameter name 1':'body string parameter value 1',
'body string parameter name 2':'body string parameter value 2',
'body int parameter name':42
},
crossDomain: true,
xhrFields:{withCredentials: true},
success: function (data)
{
//Handle API Call Success [Note: this does not mean that the action was successful, only that the server communication was successful.]
},
error: function (xhr, error, msg)
{
//Handle AJAX Error
}
});
C#.NET
Sample:
RestClient client = new RestClient("https://api.qe.co.za/[The URI you have built]");
RestRequest request = new RestRequest();
request.Method = Method.POST;
request.AddHeader("Authorization",$"Bearer {Your Access Token}");
request.AddHeader("Content-Type","application/json");
//This assumes the presence of the package NewtonsoftJson - you can serialize your JSON in other ways if you wish. This is the easiest
string jsonString = JsonConvert.SerializeObject(YourDataPacket);
request.AddParameter("application/json",jsonString,ParameterType.RequestBody);
IRestResponse rest = client.Execute(request);
if (rest.StatusCode == HttpStatusCode.OK)
{
//Handle API Call Success [Note: this does not mean that the action was successful, only that the server communication was successful.]
//Data is in rest.Content
//If you have created a matching ResultModel<T> (if the API Call returns it). EG: ResultModel<QuoteSection> And you have included the NewtonsoftJson package in your project, you can do this.
ResultModel<T> result = JsonConvert.DeserializeObject<ResultModel<T>>(rest.Content);
}
else
{
//Handle AJAX Error
}
Flutter.Dart
Sample: [Note: This example assumes that you are using null safety in your Flutter.Dart project]
import 'package:http/http.dart' as http;
import 'dart:convert';
class ApiResult{
String? status;
String? message;
int? identity;
int? total;
Map<String,dynamic>? result;
ApiResult({
this.status,
this.message,
this.identity,
this.total,
this.result,
});
factory ApiResult.fromJson(Map<String,dynamic> parsedJson){
return _ApiResult(
status: parsedJson['status'],
message: parsedJson['message'],
identity: parsedJson['identity']?.toInt() ?? 0,
total: parsedJson['total']?.toInt() ?? 0,
result: parsedJson['result'],
);
}
}
//Note: You should be using the DART version of the API call if it exists
//Note: This will throw an exeption on transmission error.
final response = await http.post(
Uri.https('https://api.qe.co.za','[The URI you have built]').
headers:{
'Authorization': 'Bearer '+[Your Access Token],
'accept':'*/*'
},
body:[Your Body Object]
);
//The result is in response.body
dynamic jsonData = json.decode(response.body);
ApiResult? result = ApiResult.fromJson(jsonData);
if (result.status == "ok"){
//Handle API Call Action Success
} else {
//Handle API Call Action failure
throw(result.message??"Unknown API Action Error");
}
DELETE requests
To use a DELETE request, you need to:
-
Add an Authorisation Header with your access token
- To get an access token, see the Login page.
- Fill in the ID in the URI (as indicated by the {}. The API help page of the DELETE request will explain the values of the parameters
- Make a web-request to the API
jQuery [Javascript]
Sample:
$.ajax(
{
url: 'https://api.qe.co.za/[The URI that you have built]',
headers:
{
"Authorization": "Bearer " + [Your Access Token], "accept": "*/*"
},
method: 'DELETE',
dataType: "json",
crossDomain: true,
xhrFields:{withCredentials: true},
success: function (data)
{
//data.status will be "ok","error", or "exception"
//if data.status != "ok" the error message will be in data.message
},
error: function (xhr, error, msg)
{
//Handle AJAX Error
}
});
C#.NET
Sample:
RestClient client = new RestClient("https://api.qe.co.za/[The URI you have built]");
RestRequest request = new RestRequest();
request.Method = Method.DELETE;
request.AddHeader("Authorization",$"Bearer {Your Access Token}");
IRestResponse rest = client.Execute(request);
if (rest.StatusCode == HttpStatusCode.OK)
{
//Handle API Call Success [Note: this does not mean that the action was successful, only that the server communication was successful.]
//The response will be in a ResultModel<string> and only status and message fields will be relevant.
}
else
{
//Handle AJAX Error
}
Flutter.Dart
Sample: [Note: This example assumes that you are using null safety in your Flutter.Dart project]
import 'package:http/http.dart' as http;
import 'dart:convert';
class ApiResult{
String? status;
String? message;
int? identity;
int? total;
Map<String,dynamic>? result;
ApiResult({
this.status,
this.message,
this.identity,
this.total,
this.result,
});
factory ApiResult.fromJson(Map<String,dynamic> parsedJson){
return _ApiResult(
status: parsedJson['status'],
message: parsedJson['message'],
identity: parsedJson['identity']?.toInt() ?? 0,
total: parsedJson['total']?.toInt() ?? 0,
result: parsedJson['result'],
);
}
}
//Note: You should be using the DART version of the API call if it exists
//Note: This will throw an exeption on transmission error.
final response = await http.delete(
Uri.https('https://api.qe.co.za','[The URI you have built]').
headers:{
'Authorization': 'Bearer '+[Your Access Token],
'accept':'*/*'
});
//The result is in response.body
dynamic jsonData = json.decode(response.body);
ApiResult? result = ApiResult.fromJson(jsonData);
if (result.status == "ok"){
//Handle API Call Action Success
} else {
//Handle API Call Action failure
throw(result.message??"Unknown API Action Error");
}