REST API
While designing REST API our goals were:
- Make JSON first-class output format.
- Build an API based solely on HTTP protocol semantics.
- Pass credentials together with request to avoid separate login calls.
- Allow cross-origin resource sharing (CORS).
- Make calls require only couple lines of code.
- Address certain design shortcomings of SOAP API
Have we reached these goals? We hope so. Want to query the Default View of a Test table in a Test API database (21995) in HTML format? Open your browser and type:
https://www.teamdesk.net/secure/api/v2/21995/Test/Default%20View/select.html
You’ll be prompted for login (type test@test.com
) and password (type pwd
) and then there is your data.
Using jQuery? Easy! Create authorization token in database’s setup section, set authtoken variable and let jQuery handle the rest.
var authtoken = "0123456789ABCDEF0123456789ABCDEF";
$.getJSON(
"https://www.teamdesk.net/secure/api/v2/21995/" + authtoken +
"/Test/Default%20View/select.json",
function(data) {
/* here we have data */
}
);
In PHP? Still easy!
$authtoken = "0123456789ABCDEF0123456789ABCDEF";
$data = json_decode(
file_get_contents(
"https://www.teamdesk.net/secure/api/v2/21995/" . $authtoken .
"/Test/Default%20View/select.json"
));
In C#?
string authtoken = "0123456789ABCDEF0123456789ABCDEF";
object data = new JavaScriptSerializer().DeserializeObject(
new WebClient().DownloadString(
"https://www.teamdesk.net/secure/api/v2/21995/" + authtoken +
"/Test/Default%20View/select.json"
));
Please note that simplicity does not mean efficiency. Samples above are dead simple but in order to make API operations more effective you may want to enable compression and caching that will require little bit more complicated web client setup.