Skip to content

Commit d9e1532

Browse files
committed
refactor: Use json instead of body
1 parent 13de490 commit d9e1532

3 files changed

Lines changed: 9 additions & 17 deletions

File tree

fly-http/src/app.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::exports::activity_flyio::fly_http::apps;
22
use crate::{API_BASE_URL, request_with_api_token};
33
use anyhow::anyhow;
44
use serde::{Deserialize, Serialize};
5-
use wstd::http::{Client, IntoBody as _, Method, StatusCode};
5+
use wstd::http::request::JsonRequest as _;
6+
use wstd::http::{Client, Method, StatusCode};
67
use wstd::runtime::block_on;
78

89
async fn put(org_slug: String, app_name: String) -> Result<apps::App, anyhow::Error> {
@@ -19,13 +20,11 @@ async fn put(org_slug: String, app_name: String) -> Result<apps::App, anyhow::Er
1920
app_name: &app_name,
2021
org_slug: &org_slug,
2122
};
22-
let body_bytes = serde_json::to_vec(&request_body)?;
2323

2424
let post_request = request_with_api_token()?
2525
.method(Method::POST)
2626
.uri(format!("{API_BASE_URL}/apps"))
27-
.header("Content-Type", "application/json")
28-
.body(body_bytes.into_body())?;
27+
.json(&request_body)?;
2928

3029
let mut response = client.send(post_request).await?;
3130

fly-http/src/machine.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ser::{
1111
MachineUpdateRequestSer, ResponseErrorSer,
1212
};
1313
use wstd::http::request::JsonRequest;
14-
use wstd::http::{Client, IntoBody as _, Method, StatusCode};
14+
use wstd::http::{Client, Method, StatusCode};
1515
use wstd::runtime::block_on;
1616

1717
// These structs are internal implementation details. They are designed to serialize
@@ -393,14 +393,11 @@ async fn create(
393393
config: fly_config,
394394
region,
395395
};
396-
let body = serde_json::to_string(&request_payload).expect("must be serializable");
397-
398396
let url = format!("{API_BASE_URL}/apps/{app_name}/machines");
399397
let request = request_with_api_token()?
400398
.method(Method::POST)
401399
.uri(url)
402-
.header("Content-Type", "application/json")
403-
.body(body.into_body())?;
400+
.json(&request_payload)?;
404401

405402
let response = Client::new().send(request).await?;
406403
if response.status().is_success() {
@@ -451,14 +448,11 @@ async fn update(
451448
config: machine_config,
452449
region,
453450
};
454-
let body = serde_json::to_string(&request_payload).expect("must be serializable");
455-
456451
let url = format!("{API_BASE_URL}/apps/{app_name}/machines/{machine_id}");
457452
let request = request_with_api_token()?
458453
.method(Method::POST)
459454
.uri(url)
460-
.header("Content-Type", "application/json")
461-
.body(body.into_body())?;
455+
.json(&request_payload)?;
462456

463457
let response = Client::new().send(request).await?;
464458
if response.status().is_success() {

fly-http/src/secret.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::exports::activity_flyio::fly_http::secrets;
22
use crate::{API_BASE_URL, request_with_api_token};
33
use anyhow::anyhow;
44
use serde::{Deserialize, Serialize};
5-
use wstd::http::{Client, IntoBody as _, Method};
5+
use wstd::http::request::JsonRequest as _;
6+
use wstd::http::{Client, Method};
67
use wstd::runtime::block_on;
78

89
async fn list_secrets(app_name: String) -> Result<Vec<secrets::Secret>, anyhow::Error> {
@@ -39,14 +40,12 @@ async fn put_secret(
3940
}
4041
let client = Client::new();
4142
let body = PutBody { value };
42-
let body = serde_json::to_vec(&body)?;
4343
let request = request_with_api_token()?
4444
.method(Method::POST)
4545
.uri(format!(
4646
"{API_BASE_URL}/apps/{app_name}/secrets/{secret_name}"
4747
))
48-
.header("Content-Type", "application/json")
49-
.body(body.into_body())?;
48+
.json(&body)?;
5049

5150
let mut response = client.send(request).await?;
5251

0 commit comments

Comments
 (0)