title: Authentication to a RESTful web service in an AngularJS 2
body: <p>i want to consume an api that return a json file, but i need to do the authentification in my header HTTP i don't know how to really do it, </p>
  
  <p>my typeScript service code is : </p>
  
  <pre><code>import {Http} from 'angular2/http';
  import 'rxjs/add/operator/map';
  import{Injectable} from 'angular2/core';
  
  @Injectable()
  export class PostService{
      constructor(private _http: Http){
      }
  
      getPosts(){
         return  this._http.get("http://jsonplaceholder.typicode.com/posts").map(res =&gt; res.json());
      }
  }
  </code></pre>
  
  <p>and my app code : </p>
  
  <pre><code>import {Component} from 'angular2/core';
  import {PostService} from './post.service';
  import { Observer } from 'rxjs/Observer';
  import {Input} from 'angular2/core';
  import {HTTP_PROVIDERS} from 'angular2/http';
  
  @Component({
      selector: 'my-app',
      template: `
      &lt;h1&gt;get webservice&lt;/h1&gt;
  
  
      `,
      providers:[PostService, HTTP_PROVIDERS]
  })
  export class AppComponent { 
  
  
      constructor(private _postService: PostService){    this._postService.getPosts().subscribe(posts =&gt; console.log(posts));
      }
  }
  
  and my api link is like : 
  
  header HTTP :
  key : Authorization
  the contents : Basic VXNlcjE6cGFzc3dvcmQ=
  </code></pre>
  
  <p>can anyone explain to me please? thank's in advance </p>