import { Injectable } from '@angular/core'; import {User} from '../dtcservice/user'; import { Observable, of } from 'rxjs'; import { HttpClient, HttpHeaders } from '@angular/common/http'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; @Injectable({ providedIn: 'root' }) export class UserService { constructor(private http: HttpClient) { } private apihost = 'http://localhost:8080'; getUsers(): Observable { return this.http.get(this.apihost+'/user'); } addUser(user:User):Observable{ return this.http.post(this.apihost+"/user",user,httpOptions); } updateUser (user: User, id:number): Observable { return this.http.put(`${this.apihost}/user/${id}`, user, httpOptions); } getUser(id: number): Observable { const url = `${this.apihost}/user/${id}`; return this.http.get(url); } deleteUser(id:number):Observable{ return this.http.delete(`${this.apihost}/user/${id}`); } }