📜  angular http - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:28.391000             🧑  作者: Mango

代码示例1
constructor(private http: HttpClient) { }

    //GET ALL
    GetAll(): Observable {
        return this.http.get(this.baseUrl + "/all");
    }
    
    //GET SINGLE
    GetSingle(id: any): Observable {
        return this.http.get(this.baseUrl + "/single/" + id);
    }
    
    //PUT
    Update(obj: Object) {
        const data = JSON.stringify(obj);
        return this.http.put(this.baseUrl, data, {
            headers: new HttpHeaders({
                "Content-Type": "application/json",
            }),
        });
    }

    //POST
    Create(obj: Object) {
        const data = JSON.stringify(obj);
        return this.http.post(this.baseUrl, data, {
            headers: new HttpHeaders({
                "Content-Type": "application/json",
            }),
        });
    }
    //DELETE
    Delete(obj: Object) {
        const data = JSON.stringify(obj);
        return this.http.delete(this.baseUrl + "/delete", data, {
            headers: new HttpHeaders({
                "Content-Type": "application/json",
            }),
        });
    }