• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript common.HttpService类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;
        }));
    }
开发者ID:beele,项目名称:WeatherGenieV2-Backend,代码行数:14,代码来源:buienradar.service.ts


示例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);
     }
 }
开发者ID:elisiondesign,项目名称:meteo-api,代码行数:18,代码来源:geo-locate.service.ts


示例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);
        }));
    }
开发者ID:beele,项目名称:WeatherGenieV2-Backend,代码行数:42,代码来源:buienradar.service.ts


示例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();
                });
        });
    }
开发者ID:beele,项目名称:WeatherGenieV2-Backend,代码行数:23,代码来源:buienradar.service.ts



注:本文中的@nestjs/common.HttpService类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript common.INestApplication类代码示例发布时间:2022-05-28
下一篇:
TypeScript common.HttpServer类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap