drogue-http-client

Crates.iodrogue-http-client
lib.rsdrogue-http-client
version0.0.2
sourcesrc
created_at2020-09-30 07:09:04.84212
updated_at2020-09-30 09:09:13.151688
descriptionAn HTTP client for embedded devices, based on drogue-network
homepagehttps://blog.drogue.io
repositoryhttps://github.com/drogue-iot/drogue-http-client
max_upload_size
id294512
size42,278
Bob McWhirter (bobmcwhirter)

documentation

README

Drogue IoT HTTP Client

CI crates.io docs.rs Matrix

An HTTP client for embedded systems, based on drogue-network. It is intended to be used in a #![no_std] environment, without an allocator.

To Do

NOTE: While is says "HTTP", it means "something that, with a bit of luck, could be interpreted as HTTP". It is far from a full HTTP 1.1 client.

  • Handle errors
  • Implement chunked encoding
  • Lots more …

Example

const ENDPOINT: &'static str = "my-host";

fn send() -> Result<(),()> {

  // socket from drogue-network, maybe with TLS
  let mut tcp = TcpSocketSinkSource::from(network, socket);

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

  let data = r#"{"temp": 1.23}"#;

  // response implementation with buffer 
  let handler = BufferResponseHandler::<U1024>::new();

  // create and execute request
  let mut req = con
    .post("/publish/telemetry")
    .headers(&[("Host", ENDPOINT), ("Content-Type", "text/json")])
    .handler(handler)
    .execute_with::<_, consts::U512>(&mut tcp, Some(data.as_bytes()));

  tcp.pipe_data(&mut req)
    .map_err(|_| ThingError::FailedToPublish)?;
    
  let (con, handler) = req.complete();
    
  log::info!(
    "Result: {} {}, Payload: {:?}",
    handler.code(),
    handler.reason(),
    from_utf8(handler.payload())
  );

  // you can do the next call with the returned `con`
}
Commit count: 11

cargo fmt