如何解决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 也会抱怨在这里使用值作为类型)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。