In this case, the API endpoint is dev-api.dtime.com.
http get https://dev-api.dtime.com
See a JS fiddle example:
Wrapped in a jquery like object:
Dependencies:
- Jquery
- Uri-templates (https://github.com/marc-portier/uri-templates)
In this case, the API endpoint is dev-api.dtime.com.
http get https://dev-api.dtime.com
See a JS fiddle example:
Wrapped in a jquery like object:
Dependencies:
{ | |
"_embedded" : {}, | |
"_links" : { | |
"dtime:root" : { | |
"rel" : "dtime:root", | |
"href" : "http://dev-api.dtime.com/" | |
}, | |
"self" : { | |
"rel" : "self", | |
"href" : "http://dev-api.dtime.com/" | |
}, | |
"curie" : { | |
"rel" : "curie", | |
"href-template" : "http://dev-api.dtime.com/docs/rels/{curie}" | |
}, | |
"dtime:current_user" : { | |
"rel" : "dtime:current_user", | |
"href" : "http://dev-api.dtime.com/user" | |
}, | |
"dtime:user" : { | |
"rel" : "dtime:user", | |
"href-template" : "http://dev-api.dtime.com/users/{user_id}" | |
}, | |
// ...snip... | |
"dtime:developers:documentation" : { | |
"rel" : "dtime:developers:documentation", | |
"href" : "http://dev-api.dtime.com/docs" | |
} | |
} | |
} |
// Relies on jquery | |
var endpoint = "http://dev-api.dtime.com/"; | |
var home = null; | |
function load_dtime(rel){ | |
if(home != null){ | |
return $.when(home) | |
} | |
else{ | |
home = $.ajax({ | |
url: endpoint | |
}) | |
return home; | |
} | |
} | |
function find_link(rel, data){ | |
for(link in data._links){ | |
if(link == rel){ | |
return data._links[rel] | |
} | |
} | |
} | |
function find_href(rel, data, tmpl){ | |
var link, template; | |
link = find_link(rel, data); | |
template = uritemplate(link["href"]); | |
} | |
// Use jquery promise to make sure api is only fetched once, | |
// and all calls relying on api are delayed until ready. | |
load_dtime().done(function(data){ | |
// One without a template | |
$('body').append("<div> Link is: " +JSON.stringify(find_link("dtime:current_user", data))+"</div>"); | |
$('body').append("<div> Href is: " +find_href("dtime:current_user", data, {user_id: 'abc'})+"</div>"); | |
// One with a template | |
$('body').append("<div> Link is: " +JSON.stringify(find_link("dtime:user", data))+"</div>"); | |
$('body').append("<div> Link is is: " +find_href("dtime:user", data, {user_id: 'abc'})+"</div>"); | |
}) |