@angular/common/http#HttpParams TypeScript Examples

The following examples show how to use @angular/common/http#HttpParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: 1inch.api.service.ts    From gnosis.1inch.exchange with MIT License 6 votes vote down vote up
public getQuote$(
    fromTokenAddress: string,
    toTokenAddress: string,
    amount: string,
  ): Observable<Quote> {

    let params = new HttpParams();
    params = params.append('fromTokenAddress', fromTokenAddress);
    params = params.append('toTokenAddress', toTokenAddress);
    params = params.append('amount', amount);

    const url = this.url + '/quote';

    return this.http.get<Quote>(url, { params }).pipe(
      delayedRetry(1000)
    );
  }
Example #2
Source File: celer-api.service.ts    From rubic-app with GNU General Public License v3.0 6 votes vote down vote up
public getEstimateAmt(
    src_chain_id: number,
    dst_chain_id: number,
    token_symbol: string,
    slippage_tolerance: number,
    amt: string,
    usr_addr?: string,
    is_pegged?: boolean
  ): Observable<EstimateAmtResponse> {
    const params = new HttpParams().appendAll({
      src_chain_id,
      dst_chain_id,
      token_symbol,
      slippage_tolerance,
      amt
    });

    if (usr_addr) {
      params.append('usr_addr', usr_addr);
    }

    if (is_pegged) {
      params.append('is_pegged', is_pegged);
    }

    return this.httpService.get<EstimateAmtResponse>(
      'v2/estimateAmt',
      params,
      this.celerApiBaseUrl
    );
  }
Example #3
Source File: location-api.service.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
private createReverseGeocodingParams(latitude: number, longitude: number, language: string): HttpParams {
    return new HttpParams({
      fromObject: {
        format: 'json',
        lat: `${latitude}`,
        lon: `${longitude}`,
        zoom: `18`,
        language,
      }
    });
  }
Example #4
Source File: spotify-auth.component.ts    From ng-spotify-importer with GNU General Public License v3.0 6 votes vote down vote up
ngOnInit(): void {
    this.activatedRoute.queryParams.subscribe(params => {
      if (params.code) {
        const body = new HttpParams()
          .set('client_id', environment.spotify.clientId)
          .set('grant_type', 'authorization_code')
          .set('code', params.code)
          .set('redirect_uri', environment.spotify.redirectUrl)
          .set('code_verifier', this.codeVerifier);

        this.http.post('https://accounts.spotify.com/api/token', body).subscribe((data: RefreshableToken) => {
          this.spotifyService.setAccessToken(data);

          if (this.spotifyService.hasAuthenticated()) {
            this.spotifyService.loadUserId().then(userId => this.userId = userId);
          }
        });
      }
    });
  }
Example #5
Source File: deployment-type-api.service.ts    From barista with Apache License 2.0 6 votes vote down vote up
public deploymentTypeIdGet(id: number, fields?: string, join?: string, cache?: number, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
        if (id === null || id === undefined) {
            throw new Error('Required parameter id was null or undefined when calling deploymentTypeIdGet.');
        }

        let queryParameters = new HttpParams({encoder: this.encoder});
        if (fields !== undefined && fields !== null) {
            queryParameters = queryParameters.set('fields', <any>fields);
        }
        if (join !== undefined && join !== null) {
            queryParameters = queryParameters.set('join[]', <any>join);
        }
        if (cache !== undefined && cache !== null) {
            queryParameters = queryParameters.set('cache', <any>cache);
        }

        let headers = this.defaultHeaders;

        // to determine the Accept header
        const httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected !== undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }


        return this.httpClient.get<DeploymentType>(`${this.configuration.basePath}/deployment-type/${encodeURIComponent(String(id))}`,
            {
                params: queryParameters,
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }
Example #6
Source File: thorchain-network.service.ts    From thorchain-explorer-singlechain with MIT License 6 votes vote down vote up
setNetwork(network: THORChainNetwork) {

    const proxy = 'https://a2wva4alb6.execute-api.us-east-1.amazonaws.com/dev/thornode';

    switch (network) {
      case THORChainNetwork.TESTNET:
        this.midgardBasePath = 'https://midgard.bepswap.com';
        this.nodeBasePath = (isDevMode()) ? 'http://44.235.130.167:1317' : proxy;
        this.network = network;
        this.nodeReqParams = new HttpParams().set('network', THORChainNetwork.TESTNET);
        break;

    /**
     * Right now default is CHAOSNET
     */
      default:
        this.midgardBasePath = 'https://chaosnet-midgard.bepswap.com';
        this.nodeBasePath = (isDevMode()) ? 'http://18.159.173.48:1317' : proxy;
        this.network = network;
        this.nodeReqParams = new HttpParams().set('network', THORChainNetwork.CHAOSNET);
        break;
    }

    this._networkUpdated.next(network);

  }
Example #7
Source File: users.api.ts    From ngx-admin-dotnet-starter with MIT License 6 votes vote down vote up
list(pageNumber: number = 1, pageSize: number = 10): Observable<any[]> {
    const params = new HttpParams()
      .set('pageNumber', `${pageNumber}`)
      .set('pageSize', `${pageSize}`);

    return this.api.get(this.apiController, { params })
      .pipe(map(data => data.map(item => {
        const picture = `${this.api.apiUrl}/${this.apiController}/${item.id}/photo`;
        return { ...item, picture };
      })));
  }
Example #8
Source File: scanner.service.ts    From RoboScan with GNU General Public License v3.0 6 votes vote down vote up
private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
        if (value == null) {
            return httpParams;
        }

        if (typeof value === "object") {
            if (Array.isArray(value)) {
                (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key));
            } else if (value instanceof Date) {
                if (key != null) {
                    httpParams = httpParams.append(key,
                        (value as Date).toISOString().substr(0, 10));
                } else {
                   throw Error("key may not be null if value is Date");
                }
            } else {
                Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive(
                    httpParams, value[k], key != null ? `${key}.${k}` : k));
            }
        } else if (key != null) {
            httpParams = httpParams.append(key, value);
        } else {
            throw Error("key may not be null if value is not object or array");
        }
        return httpParams;
    }
Example #9
Source File: oracle-explorer.service.ts    From bitcoin-s-ts with MIT License 6 votes vote down vote up
/**
   * @see https://gist.github.com/Christewart/a9e55d9ba582ac9a5ceffa96db9d7e1f#create-an-event
   * @returns announcementTLVsha256
   */
  createAnnouncement(a: OracleAnnouncement) {
    // Java does get then send to see if oracle has it already
    if (!this.oracleName.value) {
      throw(Error('Oracle Name must be set to create announcements'))
    }
    
    // This sets application/x-www-form-urlencoded when sent
    const body = new HttpParams()
      .set('oracleAnnouncementV0', a.announcementTLV)
      .set('description', a.eventName)
      .set('oracleName', this.oracleName.value)
    // TODO : Could allow user to enter URI
    
    return this.http.post<OracleExplorerResponse<string>>
      (this.url + '/announcements', body, this.getHeaders()).pipe(catchError(this.errorHandler))
  }
Example #10
Source File: api.service.ts    From blockcore-hub with MIT License 6 votes vote down vote up
/** Gets the extended public key from a certain wallet */
    getExtPubkey(data: WalletInfo): Observable<any> {
        const search = new HttpParams({
            fromObject: {
                walletName: data.walletName,
                accountName: data.accountName,
            }
        });

        return this.http
            .get(this.apiUrl + '/wallet/extpubkey', { headers: this.headers, params: search })
            .pipe(catchError(this.handleError.bind(this)))
            .pipe(map((response: Response) => response));
    }
Example #11
Source File: collection-manager-connector.service.ts    From attack-workbench-frontend with Apache License 2.0 6 votes vote down vote up
/**
     * Given a URL, retrieve the collection index at the URL
     * @param {string} url the URL of the collection index
     * @returns {Observable<CollectionIndex>} the collection index at the URL
     */
    public getRemoteIndex(url: string): Observable<CollectionIndex> {
        let params = new HttpParams({encoder: new CustomEncoder()}).set("url", url);
        return this.http.get(`${this.baseUrl}/collection-indexes/remote`, {params}).pipe(
            tap(_ => logger.log("downloaded index at", url)), // on success, trigger the success notification
            map(index => { return {
                "collection_index": index,
                "workspace": { remote_url: url }
            } as CollectionIndex }),
            catchError(this.handleError_continue<CollectionIndex>()) // on error, trigger the error notification and continue operation without crashing (returns empty item)
        )
    }
Example #12
Source File: member.service.ts    From dating-client with MIT License 6 votes vote down vote up
createParamsFromFilter(filters: Partial<IQueryParams & MembersFilter>): HttpParams {
    let params = new HttpParams();

    for (const [key, value] of Object.entries(filters).sort()) {
      if (value !== undefined && value !== ''  && value !== null) {
        const capitalizedParamKey = this.capitalizeFirstLetter(key);
        params = params.append(capitalizedParamKey, value + '');
      }
    }

    return params;
  }
Example #13
Source File: api.service.ts    From EXOS-Core with MIT License 6 votes vote down vote up
/** Gets the extended public key from a certain wallet */
    getExtPubkey(data: WalletInfo): Observable<any> {
        const search = new HttpParams({
            fromObject: {
                walletName: data.walletName,
                accountName: 'account 0',
            }
        });

        return this.http
            .get(this.apiUrl + '/wallet/extpubkey', { headers: this.headers, params: search })
            .pipe(catchError(this.handleError.bind(this)))
            .pipe(map((response: Response) => response));
    }
Example #14
Source File: config.api.service.ts    From geonetwork-ui with GNU General Public License v2.0 6 votes vote down vote up
private addToHttpParams(
    httpParams: HttpParams,
    value: any,
    key?: string
  ): HttpParams {
    if (typeof value === 'object' && value instanceof Date === false) {
      httpParams = this.addToHttpParamsRecursive(httpParams, value)
    } else {
      httpParams = this.addToHttpParamsRecursive(httpParams, value, key)
    }
    return httpParams
  }
Example #15
Source File: bom-license-exception-api.service.ts    From barista with Apache License 2.0 5 votes vote down vote up
public bomLicenseExceptionGet(fields?: string, filter?: string, or?: string, sort?: string, join?: string, perPage?: number, offset?: number, page?: number, cache?: number, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        let queryParameters = new HttpParams({encoder: this.encoder});
        if (fields !== undefined && fields !== null) {
            queryParameters = queryParameters.set('fields', <any>fields);
        }
        if (filter !== undefined && filter !== null) {
            queryParameters = queryParameters.set('filter[]', <any>filter);
        }
        if (or !== undefined && or !== null) {
            queryParameters = queryParameters.set('or[]', <any>or);
        }
        if (sort !== undefined && sort !== null) {
            queryParameters = queryParameters.set('sort[]', <any>sort);
        }
        if (join !== undefined && join !== null) {
            queryParameters = queryParameters.set('join[]', <any>join);
        }
        if (perPage !== undefined && perPage !== null) {
            queryParameters = queryParameters.set('per_page', <any>perPage);
        }
        if (offset !== undefined && offset !== null) {
            queryParameters = queryParameters.set('offset', <any>offset);
        }
        if (page !== undefined && page !== null) {
            queryParameters = queryParameters.set('page', <any>page);
        }
        if (cache !== undefined && cache !== null) {
            queryParameters = queryParameters.set('cache', <any>cache);
        }

        let headers = this.defaultHeaders;

        // authentication (oauth2) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }

        // to determine the Accept header
        const httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected !== undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }


        return this.httpClient.get<Array<BomLicenseException>>(`${this.configuration.basePath}/bom-license-exception`,
            {
                params: queryParameters,
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }