如何从 angular 服务对 propublica.org 进行 Web api 调用
How to make a web api call to propublica.org from angular service
我正在尝试通过 Angular 8 服务从 propublica.org 的会议 api 中获取信息。
作为对外部 Web 的 Http 调用的新手 api,我正在努力阅读此处找到的文档:https://projects.propublica.org/api-docs/congress-api/#requests
我能找到的关于如何拨打电话的最好的东西在这里:https://gist.github.com/renderorange/f2a8bd0ffc6eeefe79f13de684631387
但我不知道如何将其转换为使用 angular 的 HttpClient。
我正在从组件内部调用服务。我已经建立了它的结构。但是,我对 propublica 在其文档中对 jsonp 的引用感到困惑。我尝试使用 angular 的 jsonp,但它与上面 link 中的示例 javascript 调用无关。
在组件中,我正在尝试记录响应
this.CongressService
.getStateCounts()
.subscribe(data=>console.log(data));
服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { PropublicaKey } from '../../assets/config/propublica'
@Injectable({
providedIn: 'root'
})
export class CongressService {
constructor(private HttpClient:HttpClient) { }
getStateCounts() {
let options = {
url: 'https://api.propublica.org/congress/v1/states/members/party.json',
headers: {
'X-API-Key': 'my-api-key'
},
json: true
};
return this.HttpClient.jsonp(options.url, headers);
}
}
目标是记录数据,以便我知道 api 调用有效。
感谢您的帮助!
Return this.HttpClient.get(url,选项)
我正在尝试通过 Angular 8 服务从 propublica.org 的会议 api 中获取信息。
作为对外部 Web 的 Http 调用的新手 api,我正在努力阅读此处找到的文档:https://projects.propublica.org/api-docs/congress-api/#requests
我能找到的关于如何拨打电话的最好的东西在这里:https://gist.github.com/renderorange/f2a8bd0ffc6eeefe79f13de684631387
但我不知道如何将其转换为使用 angular 的 HttpClient。
我正在从组件内部调用服务。我已经建立了它的结构。但是,我对 propublica 在其文档中对 jsonp 的引用感到困惑。我尝试使用 angular 的 jsonp,但它与上面 link 中的示例 javascript 调用无关。
在组件中,我正在尝试记录响应
this.CongressService
.getStateCounts()
.subscribe(data=>console.log(data));
服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { PropublicaKey } from '../../assets/config/propublica'
@Injectable({
providedIn: 'root'
})
export class CongressService {
constructor(private HttpClient:HttpClient) { }
getStateCounts() {
let options = {
url: 'https://api.propublica.org/congress/v1/states/members/party.json',
headers: {
'X-API-Key': 'my-api-key'
},
json: true
};
return this.HttpClient.jsonp(options.url, headers);
}
}
目标是记录数据,以便我知道 api 调用有效。
感谢您的帮助!
Return this.HttpClient.get(url,选项)