-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.service.ts
More file actions
39 lines (38 loc) · 1.23 KB
/
api.service.ts
File metadata and controls
39 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Observable } from "rxjs";
@Injectable({
providedIn: "root"
})
export class ApiService {
baseUrl = "http://127.0.0.1:8000/api";
HttpHeaders = new HttpHeaders({ "Content-Type": "application/json" });
constructor(private http: HttpClient) {}
getOneMovie(id): Observable<any> {
return this.http.get(this.baseUrl + "/movies/" + id + "/", {
headers: this.HttpHeaders
});
}
getAllmovies(): Observable<any> {
return this.http.get(this.baseUrl + "/movies/", {
headers: this.HttpHeaders
});
}
updateDetails(movie): Observable<any> {
const body = { title: movie.title, desc: movie.desc, year: movie.year };
return this.http.put(this.baseUrl + "/movies/" + movie.id + "/", body, {
headers: this.HttpHeaders
});
}
createMovie(movie): Observable<any> {
const body = { title: movie.title, desc: movie.desc, year: movie.year };
return this.http.post(this.baseUrl + "/movies/", body, {
headers: this.HttpHeaders
});
}
deleteMovie(id): Observable<any> {
return this.http.delete(this.baseUrl + "/movies/" + id + "/", {
headers: this.HttpHeaders
});
}
}