You need to send a message to a Discord channel from a Rust backend but want to avoid adding a webhook library to your dependencies. This is common when you need a lightweight integration with no extra bloat or when you are building a minimal server-side application. The core problem is that Discord webhooks work over HTTP POST requests with a specific JSON payload and a custom header. This article shows you how to construct and send a valid webhook request using only Rust’s standard library — specifically the std::net::TcpStream and std::io::Write modules — so you can post messages to any Discord channel directly from your Rust code.
Webhooks are simple: you send an HTTP POST request to a unique URL provided by Discord. The URL includes a token that authenticates your request. Your Rust code must build the raw HTTP request, format the JSON body, and handle the response. No external crate is required, though you will need TLS support for HTTPS connections. The standard library alone does not include TLS, so this guide uses native-tls or rustls only for the TLS layer, not for the webhook logic itself. Alternatively, you can use the ureq crate for HTTPS without a webhook-specific library.
By the end of this article, you will be able to write a Rust function that sends a Discord webhook message using only std::net::TcpStream and a TLS wrapper. You will also learn how to handle common errors like invalid tokens, rate limits, and malformed JSON.