mirror of
https://github.com/foss42/apidash.git
synced 2025-05-29 21:06:01 +08:00
codegen(reqwest): small fix for payload and null headerList
This commit is contained in:
@ -18,7 +18,7 @@ class RustReqwestCodeGen {
|
||||
|
||||
String kTemplateBody = """
|
||||
|
||||
let payload = b"{{body}}";
|
||||
let payload = r#"{{body}}"#;
|
||||
|
||||
""";
|
||||
|
||||
@ -65,7 +65,7 @@ class RustReqwestCodeGen {
|
||||
}
|
||||
''';
|
||||
|
||||
String kStringRequestBody = """\n .body(payload.to_vec())""";
|
||||
String kStringRequestBody = """\n .body(payload)""";
|
||||
|
||||
String kStringRequestJson = """\n .json(&payload)""";
|
||||
|
||||
@ -150,14 +150,13 @@ class RustReqwestCodeGen {
|
||||
}
|
||||
|
||||
var headersList = requestModel.enabledRequestHeaders;
|
||||
if (headersList != null) {
|
||||
if (headersList != null || hasBody) {
|
||||
var headers = requestModel.enabledHeadersMap;
|
||||
if (headers.isNotEmpty) {
|
||||
if (hasBody) {
|
||||
headers[HttpHeaders.contentTypeHeader] =
|
||||
requestModel.requestBodyContentType.header;
|
||||
}
|
||||
|
||||
if (headers.isNotEmpty) {
|
||||
var templateHeaders = jj.Template(kTemplateHeaders);
|
||||
result += templateHeaders.render({"headers": headers});
|
||||
}
|
||||
|
@ -312,13 +312,14 @@ void main() {
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let url = "https://api.foss42.com/case/lower";
|
||||
|
||||
let payload = b"{
|
||||
let payload = r#"{
|
||||
"text": "I LOVE Flutter"
|
||||
}";
|
||||
}"#;
|
||||
|
||||
let response = client
|
||||
.post(url)
|
||||
.body(payload.to_vec())
|
||||
.header("content-type", "text/plain")
|
||||
.body(payload)
|
||||
.send()?;
|
||||
|
||||
println!("Status Code: {}", response.status());
|
||||
|
Reference in New Issue
Block a user