authenticate(o: Object): Observable<any> { return this.http .post(`${this.authUrl}/token`, o) .map(res => res.json()); }
getRepos() { if (this.userName) { return this._http.get('http://api.github.com/users/' + this.userName + '/repos?client_id=' + this.clientId + '&client_secret=' + this.clientSecret) .map(res => res.json()) .catch(this.handleError); } }
// private helper methods private addJwt(options?: RequestOptionsArgs): RequestOptionsArgs { // ensure request options and headers are not null options = options || new RequestOptions(); options.headers = options.headers || new Headers(); // add authorization header with jwt token let currentUser = JSON.parse(localStorage.getItem('currentUser')); if (currentUser && currentUser.token) { options.headers.append('Authorization', 'Bearer ' + currentUser.token); } return options; }
private extractData(res: Response) { try{ let body = res.json() return body.result || body } catch (error) { console.error('Error extracting api data: ' + error ) return ['Error'] } }
public save() { let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); this.http.post("http://localhost:3000/api/save", JSON.stringify(this.person), options) .map(result => result.json()) .subscribe(results => { this.location.back(); }, error => { console.error(error); }); }
public ngOnInit() { this.http.get("http://localhost:3000/api/getAll") .map(result => result.json()) .subscribe(results => { this.people = results; }, error => { console.error(error); }); }
update(table, id, data) { this.http.put(this.url + table + '/' + id, data).subscribe( data => { console.log(data); this.getAll(table); }); }
public getJSON() { return this.http .get(this._url) .map((response: Response) => response.json()); }
checkShareRequest(id : string): Promise<object>{ return this.http.get('checkShareRequest?id=' + id) .toPromise() .then(response => response.json() as any) .catch(this.handleError) }
addRider(rider: Rider): Observable<any> { return this.http .post(this.ridersUrl, rider) .map(res => res.json()); }
public save() { let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); this.http.post("http://localhost:3000/api/save", JSON.stringify(this.person), options) .map(result => result.json()) .subscribe(results => { this.location.back(); }, error => { console.error(error); }); }
public getJSON() { return this.http .get(this._url) .map((response: Response) => response.json()); }