Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

angular http

	constructor(private http: HttpClient) { }

	//GET ALL
	GetAll(): Observable<any> {
		return this.http.get(this.baseUrl + "/all");
	}
    
    //GET SINGLE
    GetSingle(id: any): Observable<any> {
		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",
			}),
		});
	}
 
PREVIOUS NEXT
Tagged: #angular #http
ADD COMMENT
Topic
Name
7+5 =