Media types

The following table shows an overview of supported Internet media types.

Media typeNameDescription
text/htmlhtmlThe HyperText Markup Language (HTML) is the publishing language of the World Wide Web. The first version of HTML was described by Tim Berners-Lee in late 1991.
application/jsonjsonJavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard. JSON defines a small set of formatting rules for the portable representation of structured data.
application/javascriptjsonp

JSONP or “JSON with padding” is a communication technique used in JavaScript programs running in web browsers to request data from a server in a different domain, something prohibited by typical web browsers because of the same-origin policy. JSONP takes advantage of the fact that browsers do not enforce the same-origin policy on <script> tags.

For an example see JSON with padding below.

The “Name” can be used with the Accept pathname suffix and parameter.

Accept header

The “Accept” request-header field can be used to specify certain media types, which are acceptable for the response, as can be seen in the following HTTP-example.

Some headers are removed for brevity.

GET /account HTTP/1.1
Accept: application/json
Authorization: Basic dGVzdEBjYXJlNGFsbC5kazp0ZXN0

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "id": "a291fc12-8d04-4ed1-8869-ed1aee1c151d",
  "type": "account",
  "href": "/account/a291fc12-8d04-4ed1-8869-ed1aee1c151d",
  "name": "test",
  "email": "test@flextrack.dk",
  "description": "Test user"
}

Accept pathname suffix

A “pathname suffix” can be used, in cases where the “Accept” request-header field is inapplicable. It can for example be used for JSONP requests, as shown in the following HTTP-example.

Some headers are removed for brevity.

GET /account.jsonp?callback=fn HTTP/1.1
Authorization: Basic dGVzdEBjYXJlNGFsbC5kazp0ZXN0

HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8

/**/ typeof fn === 'function' && fn({
  "id": "a291fc12-8d04-4ed1-8869-ed1aee1c151d",
  "type": "account",
  "href": "/account/a291fc12-8d04-4ed1-8869-ed1aee1c151d",
  "name": "Test",
  "email": "test@flextrack.dk",
  "description": "Test user"
});

Accept parameter

The “_accept” URI-parameter is an alternative, in cases where the “Accept” request-header field is inapplicable or where it should be overridden for testing purposes. The following HTTP-example shows how to make JSON-requests.

Some headers are removed for brevity.

GET /account?_accept=json HTTP/1.1
Authorization: Basic dGVzdEBjYXJlNGFsbC5kazp0ZXN0

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "id": "a291fc12-8d04-4ed1-8869-ed1aee1c151d",
  "type": "account",
  "href": "/account/a291fc12-8d04-4ed1-8869-ed1aee1c151d",
  "name": "Test",
  "email": "test@flextrack.dk",
  "description": "Test user"
}

JSON with padding

For JSONP to work, CAPI must know how to reply with JSONP-formatted results. This is accomplished by adding a dot and accept type (e.g. “.jsonp”) at the end of the pathname and a “callback”-parameter to the URL, as shown in the following HTML-example.

<!DOCTYPE html>
<html>
  <head>
    <title>JSON with padding</title>
    <meta charset="utf-8">
  </head>
  <body>
    <script>function fn(data) { console.log(data); }</script>
    <script src="/account.jsonp?callback=fn"></script>
  </body>
</html>