Skip to content

Instantly share code, notes, and snippets.

@amogram
Created May 24, 2017 15:41
Show Gist options
  • Save amogram/f8d211206cad0dcc24c68ad4bceae1be to your computer and use it in GitHub Desktop.
Save amogram/f8d211206cad0dcc24c68ad4bceae1be to your computer and use it in GitHub Desktop.
API Client Wrapper
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