The following example demonstrates a simple HTTP GET request. http.get()
returns an Observable
which has the method subscribe
. This one appends the returned data to the posts
array.
var posts = []
getPosts(http: Http):void {
this.http.get(`https://jsonplaceholder.typicode.com/posts`)
.map(response => response.json())
.subscribe(post => posts.push(post));
}