Skip to content

Commit 3ffa174

Browse files
committed
Set correct content-type on request builder
1 parent 0ccb95d commit 3ffa174

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/v1/api.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@ impl Client {
3232
}
3333
}
3434

35-
pub fn build_request(&self, method: reqwest::Method, path: &str) -> RequestBuilder {
35+
pub fn build_request(
36+
&self,
37+
method: reqwest::Method,
38+
path: &str,
39+
content_type: &str,
40+
) -> RequestBuilder {
3641
let url = format!("{}{}", &self.base_url, path);
3742

3843
let mut request = self
3944
.http_client
4045
.request(method, &url)
41-
.header(reqwest::header::CONTENT_TYPE, "application/json")
46+
.header(reqwest::header::CONTENT_TYPE, content_type)
4247
.bearer_auth(&self.api_key);
4348

4449
if is_beta_feature(path) {
@@ -49,7 +54,11 @@ impl Client {
4954
}
5055

5156
pub async fn get(&self, path: &str) -> Result<String, APIError> {
52-
let response = self.build_request(Method::GET, path).send().await.unwrap();
57+
let response = self
58+
.build_request(Method::GET, path, "application/json")
59+
.send()
60+
.await
61+
.unwrap();
5362

5463
if response.status().is_server_error() {
5564
return Err(APIError::EndpointError(response.text().await.unwrap()));
@@ -68,7 +77,7 @@ impl Client {
6877
Q: Serialize,
6978
{
7079
let response = self
71-
.build_request(Method::GET, path)
80+
.build_request(Method::GET, path, "application/json")
7281
.query(query)
7382
.send()
7483
.await
@@ -92,7 +101,7 @@ impl Client {
92101
parameters: &T,
93102
) -> Result<ResponseWrapper<String>, APIError> {
94103
let response = self
95-
.build_request(Method::POST, path)
104+
.build_request(Method::POST, path, "application/json")
96105
.json(&parameters)
97106
.send()
98107
.await
@@ -118,7 +127,7 @@ impl Client {
118127

119128
pub async fn delete(&self, path: &str) -> Result<String, APIError> {
120129
let response = self
121-
.build_request(Method::DELETE, path)
130+
.build_request(Method::DELETE, path, "application/json")
122131
.send()
123132
.await
124133
.unwrap();
@@ -132,7 +141,11 @@ impl Client {
132141

133142
pub async fn post_with_form(&self, path: &str, form: Form) -> Result<String, APIError> {
134143
let response = self
135-
.build_request(Method::POST, path)
144+
.build_request(
145+
Method::POST,
146+
path,
147+
format!("multipart/form-data; boundary={}", form.boundary()).as_str(),
148+
)
136149
.multipart(form)
137150
.send()
138151
.await
@@ -151,7 +164,7 @@ impl Client {
151164
parameters: &T,
152165
) -> Result<Bytes, APIError> {
153166
let response = self
154-
.build_request(Method::POST, path)
167+
.build_request(Method::POST, path, "application/json")
155168
.json(&parameters)
156169
.send()
157170
.await
@@ -175,7 +188,7 @@ impl Client {
175188
O: DeserializeOwned + std::marker::Send + 'static,
176189
{
177190
let event_source = self
178-
.build_request(Method::POST, path)
191+
.build_request(Method::POST, path, "application/json")
179192
.json(&parameters)
180193
.eventsource()
181194
.unwrap();
@@ -193,7 +206,7 @@ impl Client {
193206
I: Serialize,
194207
{
195208
let stream = self
196-
.build_request(Method::POST, path)
209+
.build_request(Method::POST, path, "application/json")
197210
.json(&parameters)
198211
.send()
199212
.await

0 commit comments

Comments
 (0)