- Print
- DarkLight
- PDF
Dynamic Content and Redirection
The Xponent Graph API now supports HTTP status codes with a new "dc" extension. This means that dynamic redirects and authorization can be applied to the graph API.
When the Xponent graph API is called with the string "/dc" at the end of the request URL, the response from the return node is interpreted differently. If the returned object includes a statusCode attribute, then that is the code that the Xponent Graph API will return. Any valid HTTP status code is allowed.
Some of the more popular status codes:
- 4xx - including "401 unauthorized" if access to the particular resource is not permitted
- 302 - redirect - this allows the response to be immediately redirected to a new location specified by a "redirect URL" field
Implementing Authorization
Your graph can use any of the input values, including header values, query parameters, and body, to implement an authorization scheme. If the request does not meet your authorization requirements, then you can return this literal from a Return Node:
{
"body":"Unauthorised",
"statusCode":401,
"headers":{"x-special":"things","x-auth":"XDECTFVYGUBHJN"}
}
if the call to the graph API was of the form
GET https://api.kitewheel.com/api/v1/listener/3a02aceea5c55eb3cdc2726c2a873c8b/dc
Then, the response headers should look like the one below. As you can see, the HTTP status code is set, and the x- x-headers have also been set.
< HTTP/1.1 401 Unauthorized
< Access-Control-Allow-Origin: *
< Content-Type: text/html; charset=utf-8
< Date: Fri, 01 Feb 2019 20:58:04 GMT
< ETag: W/"c-7W/48EQCx7MQfaIAfpgL92Khowc"
< x-auth: XDECTFVYGUBHJN
< x-special: things
< Content-Length: 12
< Connection: keep-alive
Dynamic Content Redirect
A similar approach is used for dynamic redirect, and here, as well as providing a statusCode of 302, you should also return a redirectURL attribute.
Hitting this API endpoint will force the browser to redirect to the specified URL. This can be used for dynamic link redirection and dynamic image content.
{
"statusCode":302,
"redirectURL": "https://kitewheel.com"
}