Created
May 24, 2017 15:41
-
-
Save amogram/f8d211206cad0dcc24c68ad4bceae1be to your computer and use it in GitHub Desktop.
API Client Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injectable} from '@angular/core'; | |
import {Http, Headers} from '@angular/http'; | |
@Injectable() | |
export class WebServiceClient { | |
constructor(private http: Http) { } | |
// Creates an Authorization Header | |
createAuthHeader(headers: Headers) { | |
headers.append('Authorization', 'Basic'); | |
} | |
// Creates an Api Version header | |
createVersionHeader(headers: Headers, version: string) { | |
headers.append('Api-Version', version); | |
} | |
// Performs a GET with version | |
get(url, version) { | |
let headers = new Headers(); | |
this.createVersionHeader(headers, version); | |
return this.http.get(url, | |
{ | |
headers: headers | |
}); | |
} | |
// Performs a POST with version | |
post(url, data, version) { | |
let headers = new Headers(); | |
this.createVersionHeader(headers, version); | |
return this.http.post(url, | |
data, | |
{ | |
headers: headers | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment