Cross site access - TextKing/textking-api GitHub Wiki

Cross-site access to the service

CORS

The TEXTKING API supports CORS (Cross Origin Resource Sharing), so you can access the service directly via JavaScript in all browsers that support CORS. Wikipedia has a list of browser engines supporting CORS. Most major browsers despite Internet Explorer support CORS at the moment, and Internet Explorer 10 will have complete CORS support, too.

JSONP

The TEXTKING API also supports JSONP for cross-site access to public resources in older browsers without support for CORS.

Attention: JSONP is only supported for public, readonly resources such as topics and languages. You can not use JSONP to perform authenticated requests or requests using a HTTP method other than GET.

In order to get a web service result as JSONP you have to add a jsonp={mycallback} query parameter to the request URI. A GET request to https://api.textking.com/v1/topic/8576549a-097f-45b3-8c59-fb3d6a03147d?jsonp=parseResponse will return the following response (formatted for better readability):

parseResponse({
    "id": "8576549a-097f-45b3-8c59-fb3d6a03147d",
    "name": "Technik / Technologie",
    "localization_language": "de",
    "links": [
        {
            "rel": "self",
            "href": "https://api.textking.dev/v1/topic/8576549a-097f-45b3-8c59-fb3d6a03147d"
        }
    ]
});

Inside your JavaScript code you can perform the requests using a JSONP library such as Lightweight JSONP. The requests above can be implemented using Lightweight JSONP with the following code:

JSONP.get('https://api.textking.com/v1/topic/8576549a-097f-45b3-8c59-fb3d6a03147d', {}, function(response) {
	console.log(response);
}, "jsonp");
⚠️ **GitHub.com Fallback** ⚠️