0.0.7 • Published 6 years ago
angular-http-offline v0.0.7
http-offline
Usage
Module
@NgModule({
declarations: [],
imports: [
HttpOfflineModule.forRoot({
baseURLs: {api: 'http://domain.com/'},
baseURLKey: 'api',
// headers: () => HttpHeaders, // set defaults headers
//cache: IHttpCache // change cacheSysyem
})
],
bootstrap: []
})
export class AppModule { }
Service
import { HttpService } from 'http-offline';
export class AppComponent {
constructor(httpService: HttpService) {
const userID: number = 3;
httpService.url('users').get<User[]>().subscribe();
httpService.url('users', userID).get<User>().subscribe();
// Pass http parameters HttpParams or Object
httpService.url('users').post<User>({name : 'Toto'}).subscribe();
httpService.url('users').get<User>({userID : userID}).subscribe();
// Change default headers HttpHeaders or Object
const newHeaders = new HttpHeaders().set('X-Accept-Version', '2.0');
httpService.url('users').headers(newHeaders).get<User>({userID : userID}).subscribe();
// Save request default save = true and force = false
httpService.url('users').headers(newHeaders).save().get<User>({userID : userID}).subscribe();
// Next get while not do a new request, it get Observable from cache
httpService.url('users').headers(newHeaders).save().get<User>({userID : userID}).subscribe();
// Save request and force to clear cache for this request
httpService.url('users').headers(newHeaders).save(true, force).get<User>({userID : userID}).subscribe();
}
}