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

Add ability to send an HTTP POST request to Ambi backend endpoint #8

Closed
jhodapp opened this issue Feb 20, 2022 · 0 comments · Fixed by #16
Closed

Add ability to send an HTTP POST request to Ambi backend endpoint #8

jhodapp opened this issue Feb 20, 2022 · 0 comments · Fixed by #16
Assignees
Labels
enhancement New feature or request

Comments

@jhodapp
Copy link
Member

jhodapp commented Feb 20, 2022

Summary

To wrap up our ESP32 WiFi proof-of-concept, the final piece is to add the ability to make an HTTP POST request with a JSON payload to an Ambi backend instance.

Feature specifics

Add a function to send an HTTP POST request to Ambi backend endpoint:

  1. Function should take the following parameters and send off a POST request to host
    • Client socket
    • Host IP address
    • HTTP port of host
    • HTTP request path (the Ambi API endpoint path minus host IP/port)
  2. It should send a JSON payload as part of the HTTP body
  3. It should handle basic server responses (HTTP 200 + 201 success status codes + 400 errors) by outputting error debug statements on the serial console
    • Note: the Ambi backend may not yes implement success response 201 after successfully responding to a POST request

Note: don't worry about implementing DNS lookups and using full on hostnames. For the PoC, we can just focus on using straight IP addresses.

Example ambi_mock_client output

Sending POST request to http://localhost:4000/api/readings/add as JSON: 
{"temperature":"16.7","humidity":"43.1","pressure":"1086","dust_concentration":"13","air_purity":"Dangerous Pollution"}
Response: Ok(
    Response {
        url: Url {
            scheme: "http",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: Some(
                Domain(
                    "localhost",
                ),
            ),
            port: Some(
                4000,
            ),
            path: "/api/readings/add",
            query: None,
            fragment: None,
        },
        status: 200,
        headers: {
            "cache-control": "max-age=0, private, must-revalidate",
            "content-length": "60",
            "content-type": "application/json; charset=utf-8",
            "date": "Wed, 23 Feb 2022 17:50:37 GMT",
            "server": "Cowboy",
            "x-request-id": "FtZ7n0Eot7jp2Q0AAV8n",
        },
    },
)

Tests

At this time, don't worry about writing unit/integration tests unless it will aid you in completing this work. We'll more intentionally focus on test writing in our next phase when we work to implement a mature ESP32 WiFi Rust crate.

@jhodapp jhodapp added the enhancement New feature or request label Feb 20, 2022
@jhodapp jhodapp changed the title Add function to send an HTTP POST request to Ambi backend endpoint Add ability to send an HTTP POST request to Ambi backend endpoint Feb 23, 2022
@jhodapp jhodapp linked a pull request May 5, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants