@knora/api
Version:
JavaScript library that handles API requests to Knora
75 lines (74 loc) • 2.51 kB
TypeScript
import { JsonConvert } from "json2typescript";
import { Observable } from "rxjs";
import { AjaxResponse } from "rxjs/ajax";
import { AjaxError } from "rxjs/internal/observable/dom/AjaxObservable";
import { KnoraApiConfig } from "../knora-api-config";
import { ApiResponseError } from "../models/api-response-error";
import { DataError } from "../models/data-error";
export declare class Endpoint {
protected readonly knoraApiConfig: KnoraApiConfig;
protected readonly path: string;
/**
* JsonConvert instance
*/
jsonConvert: JsonConvert;
/**
* The session token
*/
/**
* The session token
*/
jsonWebToken: string;
/**
* Constructor.
*/
constructor(knoraApiConfig: KnoraApiConfig, path: string);
/**
* Performs a general GET request.
*
* @param path the relative URL for the request
*/
protected httpGet(path?: string): Observable<AjaxResponse>;
/**
* 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.
*/
protected httpPost(path?: string, body?: any, contentType?: "json" | "sparql"): Observable<AjaxResponse>;
/**
* 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.
*/
protected httpPut(path?: string, body?: any, contentType?: "json"): Observable<AjaxResponse>;
/**
* 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.
*/
protected httpPatch(path?: string, body?: any, contentType?: "json"): Observable<AjaxResponse>;
/**
* Performs a general PUT request.
*
* @param path the relative URL for the request
*/
protected httpDelete(path?: string): Observable<AjaxResponse>;
/**
* Handles parsing errors.
* @param error the error class provided by us
*/
protected handleError(error: AjaxError | DataError): Observable<ApiResponseError>;
/**
* 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.
*/
private constructHeader;
}