Nestjs httpModule url 参数作为对象

问题描述

有没有办法将 url 参数传递给 nestjs 中的 httpService?我正在尝试以更易于访问的方式编写此 URL,并且不想使用 Axios,因为 nest 有一个 HTTPModule

这是我目前所拥有的,它工作正常,但看起来很糟糕:

const response = await this.httpService
      .get(`https://api.github.com/users/${username}/repos?per_page=5&sort=created:asc&client_id=${process.env.GITHUB_ID}&client_secret=${process.env.GITHUB_SECRET}`,)
      .toPromise();

我发现这个 angular 语法但它不起作用:

const response = await this.httpService.get(
      `https://api.github.com/users/${username}/repos`,params: {
        per_page: 5,sort: created:asc,client_id: process.env.GITHUB_ID,client_secret: process.env.GITHUB_SECRET
      }).toPromise();

必须有办法让它看起来更好。

解决方法

您缺少选项对象的左括号和右括号。

            Aws::SDKOptions options;
            Aws::InitAPI(options);
            {
                const Aws::String bucket_name = "bucket";
                const Aws::String object_name = "test.dll";
                const Aws::String region = "us-east-1";

                Aws::Client::ClientConfiguration config;

                if (!region.empty())
                {
                    config.region = region;
                }

                Aws::Auth::AWSCredentials credentials;
                credentials.SetAWSAccessKeyId("accesskey");
                credentials.SetAWSSecretKey("secretkey");

                Aws::S3::S3Client s3_client(credentials,config);

                Aws::S3::Model::GetObjectRequest object_request;
                object_request.SetBucket(bucket_name);
                object_request.SetKey(object_name);

                Aws::S3::Model::GetObjectOutcome get_object_outcome = s3_client.GetObject(object_request);

                if (get_object_outcome.IsSuccess())
                {
                    auto& retrieved_file = get_object_outcome.GetResultWithOwnership().GetBody();
                    int size = get_object_outcome.GetResultWithOwnership().GetContentLength() + 1;
                }
            }
            Aws::ShutdownAPI(options);

没有那个,你基本上是说使用 const response = await this.httpService.get( `https://api.github.com/users/${username}/repos`,{ params: { per_page: 5,sort: created:asc,client_id: process.env.GITHUB_ID,client_secret: process.env.GITHUB_SECRET } } ).toPromise(); 类型的变量 params(我希望 Typescript 也会抱怨在这里使用值作为类型)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...