Skip to content

Commit 9128ada

Browse files
authored
Create api.service.ts
1 parent c0ae184 commit 9128ada

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

api.service.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Injectable } from "@angular/core";
2+
import { HttpClient, HttpHeaders } from "@angular/common/http";
3+
import { Observable } from "rxjs";
4+
5+
@Injectable({
6+
providedIn: "root"
7+
})
8+
export class ApiService {
9+
baseUrl = "http://127.0.0.1:8000/api";
10+
HttpHeaders = new HttpHeaders({ "Content-Type": "application/json" });
11+
constructor(private http: HttpClient) {}
12+
getOneMovie(id): Observable<any> {
13+
return this.http.get(this.baseUrl + "/movies/" + id + "/", {
14+
headers: this.HttpHeaders
15+
});
16+
}
17+
getAllmovies(): Observable<any> {
18+
return this.http.get(this.baseUrl + "/movies/", {
19+
headers: this.HttpHeaders
20+
});
21+
}
22+
updateDetails(movie): Observable<any> {
23+
const body = { title: movie.title, desc: movie.desc, year: movie.year };
24+
return this.http.put(this.baseUrl + "/movies/" + movie.id + "/", body, {
25+
headers: this.HttpHeaders
26+
});
27+
}
28+
createMovie(movie): Observable<any> {
29+
const body = { title: movie.title, desc: movie.desc, year: movie.year };
30+
return this.http.post(this.baseUrl + "/movies/", body, {
31+
headers: this.HttpHeaders
32+
});
33+
}
34+
deleteMovie(id): Observable<any> {
35+
return this.http.delete(this.baseUrl + "/movies/" + id + "/", {
36+
headers: this.HttpHeaders
37+
});
38+
}
39+
}

0 commit comments

Comments
 (0)