Skip to content

Commit

Permalink
Update Example
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 committed Jan 25, 2025
1 parent b142de2 commit 65f9b0f
Showing 1 changed file with 4 additions and 55 deletions.
59 changes: 4 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ Additional learning resources include:
- [API Documentation](https://docs.rs/rquest)
- [Repository Examples](https://github.com/0x676e67/rquest/tree/main/examples)

## Usage
## Example

This asynchronous example uses [Tokio](https://tokio.rs) and enables some
optional features, so your `Cargo.toml` could look like this:

HTTP
This asynchronous example uses [Tokio](https://tokio.rs) and enables some optional features. Your `Cargo.toml` could look like this:

```toml
[dependencies]
tokio = { version = "1", features = ["full"] }
rquest = "2.0.0"
```

And then the code:

```rust,no_run
use rquest::{Client, Impersonate};
Expand All @@ -57,56 +56,6 @@ async fn main() -> Result<(), rquest::Error> {
}
```

WebSocket

```toml
[dependencies]
tokio = { version = "1", features = ["full"] }
rquest = { version = "2.0.0", features = ["websocket"] }
futures-util = { version = "0.3.0", default-features = false, features = ["std"] }
```

```rust,no_run
use futures_util::{SinkExt, StreamExt, TryStreamExt};
use rquest::{Impersonate, Client, Message};
#[tokio::main]
async fn main() -> Result<(), rquest::Error> {
// Build a client to impersonate Firefox133
let client = Client::builder()
.impersonate(Impersonate::Firefox133)
.build()?;
// Use the API you're already familiar with
let websocket = client
.websocket("wss://echo.websocket.org")
.send()
.await?
.into_websocket()
.await?;
let (mut tx, mut rx) = websocket.split();
tokio::spawn(async move {
for i in 1..11 {
tx.send(Message::Text(format!("Hello, World! #{i}")))
.await
.unwrap();
}
});
while let Some(message) = rx.try_next().await? {
match message {
Message::Text(text) => println!("received: {text}"),
_ => {}
}
}
Ok(())
}
```

## Overview

This project is a fork of [reqwest](https://github.com/seanmonstar/reqwest), similar to how [BoringSSL](https://github.com/cloudflare/boring) is a fork of OpenSSL. It optimizes commonly used APIs and enhances compatibility with connection pools, making it easier to switch proxies, IP addresses, and interfaces. Projects using reqwest can be migrated to rquest with minimal changes.
Expand Down

0 comments on commit 65f9b0f

Please sign in to comment.