How to make a web api call to from angular service


I’m trying to use get information from’s congress api from an Angular 8 service.

Being new to Http calls to an external web api, I’m struggling with reading the documentation found here:

The best thing I could find that shows how to make a call is here:

But I can’t figure out how to translate that to using angular’s HttpClient.

I’m calling the service from within the component. I’ve gotten as far as setting up structure of it. However, I’m confused about propublica’s reference to jsonp in their documentation. I tried using angular’s jsonp, but it doesn’t relate to the example javascript call in the link above.

In the component, I’m trying to log the response


The Service

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'

import { PropublicaKey } from '../../assets/config/propublica'

  providedIn: 'root'
export class CongressService {

  constructor(private HttpClient:HttpClient) { }

  getStateCounts() {
    let options = {
      url: '',
      headers: {
        'X-API-Key': 'my-api-key'
      json: true

    return this.HttpClient.jsonp(options.url, headers);

The goal is to log the data so I know the api call works.

Thanks for the help!


Return this.HttpClient.get(url,options)

Answered By – GergÅ‘ Éles

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.