File

libs/core/src/lib/abstract-services/api-interface.ts

Index

Methods

Methods

Protected createBasicAuthHeader
createBasicAuthHeader(token: string)
Parameters :
Name Type Optional
token string No
Returns : HttpHeaders
Protected createRequestTimespan
createRequestTimespan(timespan: Timespan)
Parameters :
Name Type Optional
timespan Timespan No
Returns : string
Protected createRequestUrl
createRequestUrl(apiUrl: string, endpoint: string, id?: string)
Parameters :
Name Type Optional
apiUrl string No
endpoint string No
id string Yes
Returns : string
import moment from 'moment';

import { Timespan } from '../model/internal/timeInterval';
import { HttpHeaders } from '@angular/common/http';

export abstract class ApiInterface {

    protected createRequestUrl(apiUrl: string, endpoint: string, id?: string) {
        // TODO Check whether apiUrl ends with slash
        let requestUrl = apiUrl + endpoint;
        if (id) { requestUrl += '/' + id; }
        return requestUrl;
    }

    protected createRequestTimespan(timespan: Timespan): string {
        return encodeURI(moment(timespan.from).format() + '/' + moment(timespan.to).format());
    }

    protected createBasicAuthHeader(token: string): HttpHeaders {
        const headers = new HttpHeaders();
        if (token) { return headers.set('Authorization', token); }
        return headers;
    }

}

result-matching ""

    No results matching ""