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

Distinguish between PUT/POST requests #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

butzist
Copy link

@butzist butzist commented Dec 15, 2022

Description

Currently, when using this library with the Realtime Database, the set() function uses a POST request and thus inserts the provided data under a new key. Is this the intended behavior?
I would have expected to set the data at the provided path (without new sub-key), ie using PUT.

Example

#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(default)]
struct SensorData {
    #[serde(rename = "t", skip_serializing_if = "Option::is_none")]
    temperature: Option<f32>,
    #[serde(rename = "h", skip_serializing_if = "Option::is_none")]
    humidity: Option<f32>,
    #[serde(rename = "d", skip_serializing_if = "Option::is_none")]
    dewpoint: Option<f32>,
}

let firebase = Firebase::new("https://xxx.firebasedatabase.app").unwrap();
let unix_time = start.duration_since(UNIX_EPOCH).unwrap().as_secs();
let data = SensorData {
    temperature: Some(42.0),
    ..Default::default()
};

firebase
    .at("weather")
    .at(&format!("{}", &unix_time))
    .set(&data)
    .await
    .expect("error writing to firebase");

Results in the following db entries:

image

Proposed changes

  • Rename old set() to insert()
  • Add new set() that uses PUT
  • Fixes code formatting

BREAKING CHANGE: set() now does PUT requests
@emreyalvac
Copy link
Owner

emreyalvac commented Dec 26, 2022

Hi,

Thanks for your time and work. Looks good!

I will release a new version soon for this improvement.

@butzist

Comment on lines +217 to +222
where
T: Serialize + DeserializeOwned + Debug,
{
let data = serde_json::to_value(&data).unwrap();
self.request(Method::PUT, Some(data)).await
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a breaking change in the lib. I suggest leave set as the POST and create another put method that will do the PUT request.

@yoramboccia-IR
Copy link

Is anyone working on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants