Guest User

Untitled

a guest
Dec 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. constructor(){
  2. this.client = new HttpClient();
  3. this.client.configure(x => {
  4. x.withBaseUrl("https://myendpoints.com/api/")
  5. x.withInterceptor({
  6. request(request){
  7. //Add auth token to header
  8. return request;
  9. }
  10. })
  11. });
  12. }
  13.  
  14. //This API endpoint has no redirect
  15. getProfile(){
  16. return this.client.get("me")
  17. .then(data => {
  18. this.profile = JSON.parse(data.response);
  19. return this.profile;
  20. });
  21. }
  22.  
  23. //This service calls an API endpoint that will redirect
  24. getContacts(){
  25. return this.client.get("me/contacts")
  26. .then(data => {
  27. this.contacts = JSON.parse(data.response);
  28. return this.contacts;
  29. })
  30. .catch(err => { console.log(err); })
  31. }
  32.  
  33. //this service calls the API endpoint directly -- no redirect
  34. getContactsDirect(accountId){
  35. return this.client.get(`account/${accountId}/contacts`)
  36. .then(data => {
  37. this.contacts = JSON.parse(data.response);
  38. return this.contacts;
  39. })
  40. .catch(err => { console.log(err); })
  41. }
Add Comment
Please, Sign In to add comment