1.0.28 • Published 2 years ago
typescript-angular-rest-client v1.0.28
typescript-angular-rest-client
Angular HTTP client with Typescript Declarative Annotations, Observables, Interceptors and Timeouts. This package is production ready.
This is an implementation for angular of typescript-rest-client : https://www.npmjs.com/package/typescript-rest-client
Installation
yarn add typescript-rest-client typescript-angular-rest-client
or
npm install typescript-rest-client typescript-angular-rest-client --save
Example
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import {
Body,
Delete,
Get,
Path,
Post,
Put,
RestClient,
} from 'typescript-rest-client';
import { v4 as uuidV4 } from 'uuid';
import { environment } from '@environments';
import { IUser } from '@model/user';
import { Client } from 'typescript-angular-rest-client';
@Injectable({
providedIn: 'root',
})
@Client({
serviceId: () => 'user',
baseUrl: () => environment.config.apis.rootUrl,
headers: () => {
return { 'x-request-type': 'API' };
},
})
export class UserService extends RestClient {
private static readonly url = 'users';
constructor(private http: HttpClient) {
super(http);
}
public getDefaultHeaders(): { [p: string]: string } {
return { 'x-request-id': uuidV4() };
}
protected requestInterceptor<T>(req: T) {
console.dir(req);
}
protected responseInterceptor<T>(res: Observable<T>): Observable<any> {
console.dir(res);
return res;
}
@Get(() => `/${UserService.url}`)
public getUsers(): Observable<IUser[]> {
return null;
}
@Get(() => `/${UserService.url}/{id}`)
public getUser(@Path('id') id: number): Observable<IUser> {
return null;
}
@Post(() => `/${UserService.url}`)
public createUser(@Body user: IUser): Observable<IUser> {
return null;
}
@Put(() => `/${UserService.url}/{id}`)
public editUser(
@Path('id') id: number,
@Body user: IUser
): Observable<IUser> {
return null;
}
@Delete(() => `/${UserService.url}/{id}`)
public deleteUser(@Path('id') id: number): Observable<void> {
return null;
}
}
1.0.28
2 years ago
1.0.26
4 years ago
1.0.25
4 years ago
1.0.27
4 years ago
1.0.25-SNAPSHOT
4 years ago
1.0.22-SNAPSHOT
4 years ago
1.0.21-SNAPSHOT
4 years ago
1.0.24-SNAPSHOT
4 years ago
1.0.23-SNAPSHOT
4 years ago
1.0.20-SNAPSHOT
4 years ago
1.0.19-SNAPSHOT
4 years ago
1.0.17-SNAPSHOT
4 years ago
1.0.18-SNAPSHOT
4 years ago
1.0.16-SNAPSHOT
4 years ago
1.0.15-SNAPSHOT
4 years ago
1.0.14-SNAPSHOT
4 years ago
1.0.13-SNAPSHOT
4 years ago
1.0.12-SNAPSHOT
4 years ago
1.0.10-SNAPSHOT
4 years ago
1.0.9-SNAPSHOT
4 years ago
1.0.11-SNAPSHOT
4 years ago
1.0.8-SNAPSHOT
4 years ago
1.0.7-SNAPSHOT
4 years ago
1.0.6-SNAPSHOT
4 years ago
1.0.5-SNAPSHOT
4 years ago
1.0.4-SNAPSHOT
4 years ago
1.0.2-SNAPSHOT
4 years ago
1.0.3-SNAPSHOT
4 years ago
1.0.1-SNAPSHOT
4 years ago
1.0.0-SNAPSHOT
4 years ago