Crate drogue_http_client

Source
Expand description

drogue-http-client aims to provide an HTTP client, in constrained no_std environment. Making use of the drogue-network API, and its network stack implementations.

An example could be to use an ESP-01 connected via UART, interfacing with the TCP stack via AT commands, wrapping that stack with a TLS layer from drogue-tls, and executing HTTPS requests on top of that stack.

§Example

use core::str::from_utf8;

use heapless::consts;

use drogue_network::tcp::TcpStack;

use drogue_http_client::tcp;
use drogue_http_client::*;

const ENDPOINT_HOST: &'static str = "my-server";
const ENDPOINT_PORT: u16 = 8080;


fn publish() -> Result<(),()> {
    let (mut network, mut socket) = connect_to_server(ENDPOINT_HOST, ENDPOINT_PORT);
    let mut tcp = tcp::TcpSocketSinkSource::from(&mut network, &mut socket);

    let con = HttpConnection::<consts::U1024>::new();

    let handler = BufferResponseHandler::<consts::U512>::new();

    let mut req = con.post("/my/path")
        .headers(&[
            ("Content-Type", "text/plain"),
            ("Host", ENDPOINT_HOST),
        ])
        .handler(handler)
        .execute_with::<_, consts::U256>(&mut tcp, Some(b"payload"));

    tcp.pipe_data(&mut req)?;

    let (con, handler) = req.complete();

    println!("Response: {} {}", handler.code(), handler.reason());
    println!("{:?}", from_utf8(handler.payload()));

    Ok(())
}

Modules§

tcp
TCP stack implementation of Sink and Source.

Structs§

BufferResponseHandler
A response handler, that will buffer all data.
HttpConnection
An HTTP connection.
NoOpResponseHandler
A no-op response handler.
Request
The ongoing HTTP request.
RequestBuilder
A request builder, which helps to gather all required information before executing the request.
Response
The HTTP response header.

Traits§

ResponseHandler
A trait handling responses to an HTTP request.
Sink
A sink to send HTTP requests to
Source
A source of data for the HTTP response