import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { RegisterUser } from '../shared/register-user'; import { LoginUser } from '../shared/login-user'; import { User } from '../shared/user'; import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class BackendService { httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; constructor(private http: HttpClient) {} endPoint: string = "http://localhost:5240/api/"; RegisterUser(registerUser: RegisterUser) { return this.http.post(`${this.endPoint}Authentication/Register`, registerUser, this.httpOptions); } LoginUser(loginUser: LoginUser): Observable<User> { return this.http.post<User>(`${this.endPoint}Authentication/Login`, loginUser, this.httpOptions); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter