Nestjs using axios

后端 未结 3 1233
[愿得一人]
[愿得一人] 2021-02-05 19:56

This simple demo has an error https://docs.nestjs.com/techniques/http-module

import { Get, Controller, HttpService } fro         


        
3条回答
  •  隐瞒了意图╮
    2021-02-05 20:58

    You have to make sure to handle your responses as a JSON you can return it as a promise and get the data, use one of both or HttpService or axios

    import { Get, Controller, HttpService } from '@nestjs/common';
    @Controller()
    export class AppController {
      constructor(private readonly http: HttpService) {}
      @Get()
          root(): {
            return this.httpClient.get('https://api.github.com/users/quen2404')
            .toPromise()
            .then(res => res.data)
            .catch(err => /*handle error*/)
          }
    }
    

提交回复
热议问题