Skip to content

Instantly share code, notes, and snippets.

@p4535992
Forked from cloudmark/httpService.ts
Created February 3, 2020 08:33
Show Gist options
  • Select an option

  • Save p4535992/afd1b0e2440098b1cdecdc44c2b2d6bb to your computer and use it in GitHub Desktop.

Select an option

Save p4535992/afd1b0e2440098b1cdecdc44c2b2d6bb 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