#twilight #discord #discord-api #api-client #rest-client

twilight-http

Discord REST API client for the Twilight ecosystem

92 releases

0.16.0-rc.1 Feb 21, 2024
0.15.4 Sep 10, 2023
0.15.2 Apr 27, 2023
0.15.1 Feb 26, 2023
0.2.5 Nov 29, 2020

#12 in HTTP client

Download history 5728/week @ 2024-08-15 13721/week @ 2024-08-22 9029/week @ 2024-08-29 9948/week @ 2024-09-05 6567/week @ 2024-09-12 10272/week @ 2024-09-19 17801/week @ 2024-09-26 5350/week @ 2024-10-03 10396/week @ 2024-10-10 11702/week @ 2024-10-17 7204/week @ 2024-10-24 8617/week @ 2024-10-31 5315/week @ 2024-11-07 44010/week @ 2024-11-14 10297/week @ 2024-11-21 10265/week @ 2024-11-28

70,495 downloads per month
Used in 18 crates (17 directly)

ISC license

2.5MB
58K SLoC

twilight-http

codecov badge discord badge github badge license badge rust badge

HTTP support for the twilight ecosystem.

Examples

There are a few usage examples located in the root of the twilight repository.

Features

Decompression

The decompression feature enables brotli decompression support via the brotli crate.

This is enabled by default.

Deserialization

twilight-http supports serde_json and simd-json for deserializing responses.

simd-json

The simd-json feature enables simd-json support to use simd features of modern cpus to deserialize responses faster. It is not enabled by default.

To use this feature you need to also add these lines to <project root>/.cargo/config:

[build]
rustflags = ["-C", "target-cpu=native"]

You can also set the environment variable RUSTFLAGS="-C target-cpu=native". If you enable both serde_json and simd-json at the same time, then simd-json will be used.

To enable simd-json, do something like this in your Cargo.toml:

[dependencies]
twilight-http = { default-features = false, features = ["rustls-native-roots", "simd-json"], version = "0.2" }

TLS

Note: not enabling any TLS feature is supported for use behind a proxy; Discord's API is HTTPS only.

twilight-http has features to enable HTTPS connectivity with hyper. These features are mutually exclusive. rustls-native-roots is enabled by default.

native-tls

The native-tls feature uses a HTTPS connector provided by hyper-tls.

To enable native-tls, do something like this in your Cargo.toml:

[dependencies]
twilight-http = { default-features = false, features = ["native"], version = "0.2" }

rustls-native-roots

The rustls-native-roots feature uses a HTTPS connector provided by hyper-rustls, which uses rustls as the TLS backend, and enables its native-tokio feature, which uses rustls-native-certs for root certificates.

This is enabled by default.

rustls-webpki-roots

The rustls-webpki-roots feature uses a HTTPS connector provided by hyper-rustls, which uses rustls as the TLS backend, and enables its webpki-tokio feature, which uses webpki-roots for root certificates.

This should be preferred over rustls-native-roots in Docker containers based on scratch.

Trust-DNS

The hickory feature enables hyper-hickory, which replaces the default GaiResolver in hyper. hyper-hickory instead provides a fully async DNS resolver on the application level.

Dependencies

~8–24MB
~426K SLoC