blob: 92524a9ce624fbc3c0498de3414d6f1ea5a6de12 (
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
28
29
30
31
32
33
|
import AbstractAPI from './abstract-api.js';
type APIOptions = Record<string, unknown>;
// Actual JSONAPI object
class JSONAPI extends AbstractAPI
{
constructor(version: number = 1) {
super(`jsonapi.php/v${version}`);
}
encodeData (data: object, method: string): string|null|object {
data = super.encodeData(data);
if (['DELETE', 'GET', 'HEAD'].includes(method)) {
return data;
}
if (Object.keys(data).length === 0) {
return null;
}
return JSON.stringify(data);
}
request (url: string, options: APIOptions = {}) {
options.contentType = 'application/vnd.api+json';
return super.request(url, options);
}
}
export default JSONAPI;
export const jsonapi: JSONAPI = new JSONAPI();
|