Skip to content

Instantly share code, notes, and snippets.

@fcschmidt
Last active December 4, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcschmidt/e57b8d687b17b67209d5396e04dbe3ec to your computer and use it in GitHub Desktop.
Save fcschmidt/e57b8d687b17b67209d5396e04dbe3ec to your computer and use it in GitHub Desktop.
import { HttpClient, HttpHeaders, HttpHeaderResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
// import { Observable } from 'rxjs/Observable';
// import { resolveDefinition } from '@angular/core/src/view/util';
import 'rxjs/add/operator/map';
/*
Generated class for the RestApiProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class RestApiProvider {
private API_URL = "http://localhost:3000/api/user";
constructor(private http: HttpClient) {
console.log('Hello RestApiProvider Provider');
}
postPergamum(username: string, password: string) {
return new Promise((resolve, reject) => {
var data = {
"username": username,
"password": password
};
let headers = new HttpHeaders();
// headers.append("Content-type", "application/json");
// let options = new HttpHeaderResponse({ headers: headers});
headers.set("Content-Type", "application/json");
this.http.post(this.API_URL, JSON.stringify(data), {headers: headers})
.subscribe((result: any) => {
resolve(result.json());
}, (error) => {
reject(error.json());
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment