Nicer text/* response values
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với ResponseValue được tạo và đường dẫn into_inner_stream của nó được hiển thị trong issue, sau đó so sánh các API text() và json() của reqwest::Response mà nó tham chiếu. Làm rõ liệu kết quả mong muốn là một API đơn giản hơn cho body dạng văn bản hay một ví dụ về việc thu thập stream. Công việc được xem là hoàn tất khi cách tiếp cận được chọn giúp các response văn bản cơ bản trở nên dễ xử lý và được minh họa rõ ràng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
For text response values, it is not very ergonomic to get the text (the response body).
Example
Consider the following API:
openapi: "3.0.0"
info:
title: Hello World
version: "1.0"
paths:
/hello:
get:
operationId: getHello
responses:
"200":
description: Get hello
content:
text/plain:
schema:
type: string
example: Hello World
Progenitor generates the following code:
#[allow(clippy::all)]
impl Client {
///Sends a `GET` request to `/hello`
pub async fn get_hello<'a>(&'a self) -> Result<ResponseValue<ByteStream>, Error<()>> {
let url = format!("{}/hello", self.baseurl,);
#[allow(unused_mut)]
let mut request = self.client.get(url).build()?;
let result = self.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => Ok(ResponseValue::stream(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
To integrate this in my code and read the response, I need something like this:
use futures::StreamExt;
async fn test_hello() {
let client = Client::new("baseurl");
let resp_val = client.get_hello().await.unwrap();
let mut stream = resp_val.into_inner_stream();
let mut bytes: Vec<u8> = Vec::new();
while let Some(n) = stream.next().await {
let b = n.unwrap();
bytes.extend_from_slice(&b);
}
let hello = String::from_utf8(bytes).unwrap();
dbg!("{}", hello);
}
Expected behaviour
That's not very ergonomic. Sure, I know at a high-level that I need to collect the byte stream into a vector. But it still took me a while to figure out the exact types to make it compile...
It would be nice if there were a more obvious API that makes it easier to "just get the body string".
reqwest::Response already has useful methods like text() or json(). But since progenitor's client hides the reqwest::Response from me, I cannot use those.
Alternatively, it would be nice to have an example somewhere that shows how to read such basic text responses.
Version
(cargo-)progenitor 0.7.0
- Ngôn ngữ chính
- Rust
- Star
- 1k
- Fork
- 142
- Merge trung bình
- 19 giờ 13 phút
- Pull request đã merge (30 ngày)
- 16
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của oxidecomputer/progenitor
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
oxidecomputer/progenitor#1345 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Generated client treats a declared 304 Not Modified as UnexpectedResponseCó thể đã có người làm @jjant đã nhận 6 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
oxidecomputer/progenitor#1462 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 58/100
oxidecomputer/progenitor#1457 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
oxidecomputer/progenitor#1444 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
oxidecomputer/progenitor#1382 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của oxidecomputer/progenitor
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anomalyco/rune#2432 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
[Bug]: Add Data's question says "Link to the file" for a GeoPackage where small tables are copiedĐang mởunconfirmed possible issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jerney-nexus/epikrise#364 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Yeachan-Heo/gajae-code#8058 ·
Maintainer thường phản hồi trong vòng 1 ngày