UNPKG

2.34 kBTypeScriptView Raw
1import FollowablePromise from './followable-promise';
2import Representor from './representor/base';
3import Resource from './resource';
4import { ContentType, KettingInit } from './types';
5import './utils/fetch-polyfill';
6/**
7 * The main Ketting client object.
8 */
9export default class Ketting {
10 /**
11 * The url from which all discovery starts.
12 */
13 bookMark: string;
14 /**
15 * Here we store all the resources that were ever requested. This will
16 * ensure that if the same resource is requested twice, the same object is
17 * returned.
18 */
19 resourceCache: {
20 [url: string]: Resource;
21 };
22 /**
23 * Content-Type settings and mappings.
24 *
25 * See the constructor for an example of the structure.
26 */
27 contentTypes: ContentType[];
28 /**
29 * The helper class that calls fetch() for us
30 */
31 private fetchHelper;
32 constructor(bookMark: string, options?: KettingInit);
33 /**
34 * This function is a shortcut for getResource().follow(x);
35 */
36 follow(rel: string, variables?: object): FollowablePromise;
37 /**
38 * Returns a resource by its uri.
39 *
40 * This function doesn't do any HTTP requests. The uri is optional. If it's
41 * not specified, it will return the bookmark resource.
42 *
43 * If a relative uri is passed, it will be resolved based on the bookmark
44 * uri.
45 */
46 go(uri?: string): Resource;
47 /**
48 * Returns a resource by its uri.
49 *
50 * This function doesn't do any HTTP requests. The uri is optional. If it's
51 * not specified, it will return the bookmark resource.
52 */
53 getResource(uri?: string): Resource;
54 /**
55 * This function does an arbitrary request using the fetch API.
56 *
57 * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch}
58 */
59 fetch(input: string | Request, init?: RequestInit): Promise<Response>;
60 /**
61 * This function returns a representor constructor for a mime type.
62 *
63 * For example, given text/html, this function might return the constructor
64 * stored in representor/html.
65 */
66 getRepresentor(contentType: string): typeof Representor;
67 /**
68 * Generates an accept header string, based on registered Resource Types.
69 */
70 getAcceptHeader(): string;
71 beforeRequest(request: Request): void;
72}