import { Http } from '@angular/http'; constructor(private http: Http) {} this.http.get('https://jsonplaceholder.typicode.com/users') .subscribe(data => { console.log(data.json()); });
import { Http, Headers, RequestOptions } from '@angular/http'; constructor(private http: Http) {} const headers = new Headers({ 'Content-Type': 'application/json' }); const options = new RequestOptions({ headers: headers }); const body = { name: 'John', age: 35 }; this.http.post('https://jsonplaceholder.typicode.com/users', body, options) .subscribe(data => { console.log(data.json()); });This code makes a POST request to a JSON placeholder API with a JSON payload containing a name and age. It logs the response data to the console. It also sets the headers for the request using the HttpHeaders package library. Overall, the typescript angular2.http Http module is a powerful tool for making HTTP requests and handling responses. It's a great package library to help with modern day web development.