michussj07

http-cars.service.ts

Feb 13th, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import {HttpClient} from "@angular/common/http";
  3. import {Observable} from "rxjs";
  4. import {ConfigService} from '../../services/config.service';
  5.  
  6. @Injectable({
  7. providedIn: 'root'
  8. })
  9. export class HttpCarsService {
  10.  
  11. constructor(private httpService:HttpClient, private configService: ConfigService) { }
  12.  
  13. private _car_url = this.configService._api_url +'/cars';
  14. private _car1_url = this.configService._api_url +'/cars?id=';
  15.  
  16. public getCarList(): Observable<any> {
  17. return this.httpService.get(this._car_url +'/all');
  18. }
  19.  
  20. public createCar(car: object): Observable<object> {
  21. return this.httpService.post(this._car_url, car);
  22. }
  23.  
  24. public deleteCar(id: number): Observable<object> {
  25. return this.httpService.delete(this._car1_url + id);
  26. }
  27.  
  28. public getCar(id: number): Observable<object> {
  29. return this.httpService.get(this._car1_url + id);
  30. }
  31.  
  32. updateCar(id: number, value: any): Observable<object> {
  33. return this.httpService.put(this._car1_url + id, value);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment