@dasch-swiss/dsp-js
Version:
JavaScript library that handles API requests to Knora
106 lines (105 loc) • 3.53 kB
TypeScript
import { JsonConvert } from "json2typescript";
import { Observable } from "rxjs";
import { AjaxError, AjaxResponse } from "rxjs/ajax";
import { KnoraApiConfig } from "../knora-api-config";
import { DataError } from "../models/data-error";
/**
* HTTP Headers to be sent with the request.
*
* Note that Authorization and Content-Type are handled
* by the method `constructHeader`.
*
* @category Internal
*/
export interface IHeaderOptions {
[index: string]: string;
}
/**
* @category Internal
*/
export declare class Endpoint {
protected readonly knoraApiConfig: KnoraApiConfig;
protected readonly path: string;
readonly maxRetries = 0;
readonly delay = 500;
readonly retryOnErrorStatus: number[];
/**
* JsonConvert instance
*/
jsonConvert: JsonConvert;
/**
* The session token
*/
get jsonWebToken(): string;
/**
* The session token
*/
set jsonWebToken(value: string);
/**
* Constructor.
*/
constructor(knoraApiConfig: KnoraApiConfig, path: string);
/**
* Performs a general GET request.
*
* @param path the relative URL for the request
* @param headerOpts additional headers, if any.
*/
protected httpGet(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>>;
/**
* Performs a general POST request.
*
* @param path the relative URL for the request
* @param body the body of the request, if any.
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
*/
protected httpPost(path?: string, body?: any, contentType?: "json" | "sparql", headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>>;
/**
* Performs a general PUT request.
*
* @param path the relative URL for the request
* @param body the body of the request
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
*/
protected httpPut(path?: string, body?: any, contentType?: "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>>;
/**
* Performs a general PATCH request.
*
* @param path the relative URL for the request
* @param body the body of the request
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
*/
protected httpPatch(path?: string, body?: any, contentType?: "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>>;
/**
* Performs a general PUT request.
*
* @param path the relative URL for the request.
* @param headerOpts additional headers, if any.
*/
protected httpDelete(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>>;
/**
* Handles parsing errors.
* @param error the error class provided by us
*/
protected handleError(error: AjaxError | DataError): Observable<never>;
/**
* Creates a header for a HTTP request.
* If the client has obtained a token, it is included.
*
* @param contentType Sets the content type, if any.
* @param headerOpts additional headers, if any.
*/
private constructHeader;
/**
* Sets ajax request
* @param path string
* @param method 'GET', 'POST', 'PUT', 'PATCH' or 'DELETE'
* @param [body] any
* @param [headers] IHeaderOptions
* @returns AjaxRequest object
*/
private setAjaxRequest;
}