aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/jsonapi.js
blob: bcd954f201cafa9fe0270b2f3304aea8fe56582b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import AbstractAPI from './abstract-api.js';

// Actual JSONAPI object
class JSONAPI extends AbstractAPI
{
    constructor(version = 1) {
        super(`jsonapi.php/v${version}`);
    }

    encodeData (data) {
        data = super.encodeData(data);

        if (Object.keys(data).length === 0) {
            return null;
        }

        return JSON.stringify(data);
    }

    request (url, options = {}) {
        options.contentType = 'application/vnd.api+json';
        return super.request(url, options);
    }
}

export default JSONAPI;
export const jsonapi = new JSONAPI();