pmtpenza

Untitled

Jul 5th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import { HttpClient, HttpParams } from '@angular/common/http';
  2. import { Injectable } from '@angular/core';
  3.  
  4. import { BASE_URL, TOKEN } from '../constants/api';
  5.  
  6. /**
  7. * Api is a generic REST Api handler. Set your API url first.
  8. */
  9. @Injectable()
  10. export class Api {
  11.  
  12. constructor(public http: HttpClient) {
  13. }
  14.  
  15. get(endpoint: string, params?: any) {
  16. let paramsQuery = '?';
  17. for (let k in params) {
  18. paramsQuery += `&${k}=${params[k]}`;
  19. }
  20. paramsQuery += '&mode=json';
  21. paramsQuery += '&lang=ru';
  22. paramsQuery += `&appid=${TOKEN}`;
  23.  
  24. return this.http.get(BASE_URL + '/' + endpoint + paramsQuery);
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment