Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #26. Allow endpoints to specify a serialization function. #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cloudflare/src/framework/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ where
fn body(&self) -> Option<BodyType> {
None
}
fn serialized_body(&self) -> Option<String> {
match self.body() {
Some(body) => Some(serde_json::to_string(&body).unwrap()),
None => None
}
}
fn url(&self, environment: &Environment) -> Url {
Url::from(environment).join(&self.path()).unwrap()
}
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl<'a> ApiClient for HttpApiClient {
)
.query(&endpoint.query());

if let Some(body) = endpoint.body() {
request = request.body(serde_json::to_string(&body).unwrap());
if let Some(body) = endpoint.serialized_body() {
request = request.body(body);
request = request.header(reqwest::header::CONTENT_TYPE, endpoint.content_type());
}

Expand Down