本文整理汇总了TypeScript中@nestjs/common.HttpService类的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpService类的具体用法?TypeScript HttpService怎么用?TypeScript HttpService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpService类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ForecastRain
getRainPrediction3Hours(lat: number, lon: number): Observable<ForecastRain[]> {
const result$ = this.httpService.get('https://graphdata.buienradar.nl/forecast/json/?lat=' + lat + '&lon=' + lon);
return result$.pipe(map((data: AxiosResponse) => {
const rainForecasts: ForecastRain[] = [];
if (data.data && data.data.forecasts) {
for (const forecast of data.data.forecasts) {
rainForecasts.push(new ForecastRain(moment(forecast.utcdatetime), forecast.precipitation));
}
}
return rainForecasts;
}));
}
示例2: locateIp
private async locateIp(ip: string = ''): Promise<Coordinates> {
try {
// Note: ip-api returns 200 OK even on invalid requests.
const data = await this.http.get(`http://ip-api.com/json/${ip}`).toPromise();
if (data['data'].status === 'fail') {
throw new Error(data['data'].message);
}
const point = {
lat: data['data'].lat,
lng: data['data'].lon,
};
return point;
}
catch (e) {
const message = e !== undefined ? e : 'IP location service request failed.';
throw new Error(message);
}
}
示例3: ForecastHour
getForecastedWeather(id: number): Observable<Forecast> {
const result$ = this.httpService.get('https://api.buienradar.nl/data/forecast/1.1/all/' + id);
return result$.pipe(map((data: AxiosResponse) => {
const days: ForecastDay[] = [];
for (const forecastedDay of data.data.days) {
const hours: ForecastHour[] = [];
if (forecastedDay.hours && forecastedDay.hours.length > 0) {
for (const forecastedHour of forecastedDay.hours) {
hours.push(
new ForecastHour(
// Times are in UTC!
moment(forecastedHour.date),
forecastedHour.temperature, forecastedHour.feeltemperature,
forecastedHour.iconcode, this.convertForecastIconCodeToWeatherCondition(forecastedHour.iconcode),
forecastedHour.windspeed, forecastedHour.beaufort, forecastedHour.winddirection,
forecastedHour.humidity, forecastedHour.precipitation, forecastedHour.precipitationmm,
forecastedHour.uvindex, forecastedHour.sunshine, forecastedHour.sunpower,
),
);
}
}
days.push(
new ForecastDay(
// Times are in UTC!
moment(forecastedDay.date),
moment(forecastedDay.sunrise), moment(forecastedDay.sunset),
forecastedDay.temperature, forecastedDay.feeltemperature, forecastedDay.mintemp, forecastedDay.maxtemp,
forecastedDay.iconcode, this.convertForecastIconCodeToWeatherCondition(forecastedDay.iconcode),
forecastedDay.windspeed, forecastedDay.beaufort, forecastedDay.winddirection,
forecastedDay.precipitation, forecastedDay.uvindex,
hours,
),
);
}
return new Forecast(data.data.location.lat, data.data.location.lon, data.data.altitude, data.data.elevation, days);
}));
}
示例4: findLocationId
findLocationId(city: string): Observable<City[]> {
const uri = 'https://api.buienradar.nl/data/search/1.0/?query=' + city + '&country=BE&locale=nl-BE';
const result$: Observable<AxiosResponse> = this.httpService.get(uri);
return Observable.create((obs) => {
const cities: City[] = [];
result$.subscribe((data: AxiosResponse) => {
const dataIndex: number = data.data.length > 1 ? (data.data.length - 1) : 0;
if (data.data.length > 0) {
for (const singleCity of data.data[dataIndex].results) {
const uriPieces: string[] = singleCity.uri.split('/');
cities.push(new City(Number(uriPieces[uriPieces.length - 1]), singleCity.main, singleCity.sub));
}
}
}, (error) => {
console.log(error);
},
() => {
obs.next(cities);
obs.complete();
});
});
}