Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- constructor(){
- this.client = new HttpClient();
- this.client.configure(x => {
- x.withBaseUrl("https://myendpoints.com/api/")
- x.withInterceptor({
- request(request){
- //Add auth token to header
- return request;
- }
- })
- });
- }
- //This API endpoint has no redirect
- getProfile(){
- return this.client.get("me")
- .then(data => {
- this.profile = JSON.parse(data.response);
- return this.profile;
- });
- }
- //This service calls an API endpoint that will redirect
- getContacts(){
- return this.client.get("me/contacts")
- .then(data => {
- this.contacts = JSON.parse(data.response);
- return this.contacts;
- })
- .catch(err => { console.log(err); })
- }
- //this service calls the API endpoint directly -- no redirect
- getContactsDirect(accountId){
- return this.client.get(`account/${accountId}/contacts`)
- .then(data => {
- this.contacts = JSON.parse(data.response);
- return this.contacts;
- })
- .catch(err => { console.log(err); })
- }
Add Comment
Please, Sign In to add comment