This project has been archived. If you're curious, check out one of my latest courses:

If you work with JavaScript, check out the fetch use cases and JavaScript projects.

Thank you! — Jad Joubran

Angular Http

Let's build an Angular Service that consumes this endpoint

Angular Service

posts.service.ts
import { Injectable } from '@angular/core';
import { Http }       from '@angular/http';

import { Observable }     from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Injectable()
export class PostsService {

  constructor(private http: Http) {}

  getAll(): Observable {
    return this.http
               .get('api/posts')
               .map(response => response.json());
  }
}