Http Decorators (Deprecated)
Deprecation Notice - This component will be deprecated in favor of a different implementation View Doc
It is a framework of decorators on top of the angular [HttpClient] or covalent [TdHttpService] to enhance your services and give them Http capabilities.
Usage
Example:
import { Injectable } from '@angular/core';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import {
mixinHttp,
TdGET,
TdPOST,
TdBody,
TdParam,
TdResponse,
TdQueryParams,
} from '@covalent/http';
@Injectable()
export class TestHttpService extends mixinHttp(class {}, {
baseUrl: 'www.mybaseurl.com',
baseHeaders: new HttpHeaders({ 'Accept': 'application/json' }),
}) {
@TdGET({
path: '/myitems',
options: {
observe: 'response',
},
})
getResponse(): Observable<HttpResponse<any>> { return; }
@TdGET({
path: '/myitems',
})
getParsedResponse(@TdQueryParams() queryParams?: HttpParams): Observable<HttpResponse<any>> { return; }
@TdGET({
path: '/myitems',
})
getMappedResponse(@TdResponse() response?: Observable<HttpResponse<any>>): Observable<number> {
return response.pipe(
map((data: any) => {
return data.items.length;
}),
);
}
@TdGET({
path: '/myitems/:id',
})
get(@TdParam('id') id: string,
@TdResponse() response?: Observable<HttpResponse<any>>): Observable<any> { return; }
@POST({
path: '/myitems',
})
create(@TdBody() body: any,
@TdResponse() response?: Observable<HttpResponse<any>>): Observable<any> {
return response.pipe(
map((data: any) => {
return {
name: data.MyName,
};
}),
);
}
}