Skip to content

Instantly share code, notes, and snippets.

@cloudmark
Created May 9, 2017 10:49
Show Gist options
  • Save cloudmark/b95f82eb6f0e4ced4893a7e4f5f46ecc to your computer and use it in GitHub Desktop.
Save cloudmark/b95f82eb6f0e4ced4893a7e4f5f46ecc to your computer and use it in GitHub Desktop.
HttpService
export class HttpService {
constructor(private http: Http) {}
public getSingle<T>(clazz: { new(): T }, url: string, headers?: {}): Promise<T> {
return new Promise((resolve, reject) => {
this.http.get(url, this.getHeaders(headers)).toPromise().then((response: any) => {
let body = response.json();
if (body) {
resolve(MapUtils.deserialize(clazz, body));
} else {
resolve(new clazz());
}
},(reject) => {});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment