Skip to content

Commit eb6eaf9

Browse files
committed
2.0.0
This major release of Surf contains substantial improvements through a variety of changes and additions. (Note: this is a cumulative list of changes since Surf 1.0.3) Notable mentions include: - Uses stable standard library `futures`! - Much more type compatibility with Tide via http-types! - Re-usable `Client` which is able to make use of connection pooling under the hood. - Reduced generics for `Client` and `Middleware`. - Re-worked `Middleware` to use `async_trait`.
1 parent c1feba5 commit eb6eaf9

File tree

2 files changed

+170
-1
lines changed

2 files changed

+170
-1
lines changed

CHANGELOG.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,175 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
77

88
## [Unreleased]
99

10+
## [2.0.0] - 2020-10-05
11+
12+
[Docs](https://docs.rs/surf/2.0.0)
13+
14+
This major release of Surf contains substantial improvements through a variety of changes and additions.
15+
16+
_(Note: this is a cumulative list of changes since Surf 1.0.3)_
17+
18+
Notable mentions include:
19+
- Uses stable standard library [`futures`][]!
20+
- Much more type compatibility with [Tide][] via [http-types][]!
21+
- Re-usable `Client` which is able to make use of connection pooling [under the hood](https://github.com/http-rs/http-client).
22+
- Reduced generics for `Client` and `Middleware`.
23+
- Re-worked `Middleware` to use [`async_trait`][].
24+
25+
### Major Changes
26+
Surf 2 contains some large API changes, as noted here:
27+
28+
#### http-types
29+
30+
Surf has switched the common backing type interface (`surf::http`) from the [http][] (`hyperium/http`) crate to [http-types][], which covers a larger set of HTTP-related functionality than `hyperium/http` does, and allows Surf to use the [url standard][].
31+
32+
This affects any type that came from `surf::http`, such as `StatusCode` ([old][StatusCode http]|[new][StatusCode http-types]), and includes some new patterns, such as [`Body`][].
33+
34+
For more information, see [this blog post](https://blog.yoshuawuyts.com/async-http/#shared-abstractions).
35+
36+
#### Errors
37+
38+
`surf::Exception`, which was a plain `Box<dyn Error + Send + Sync + 'static>`, is no more.
39+
40+
Surf now exports a structured [`surf::Error`][] type, which holds a `StatusCode` alongside a dynamic error object.
41+
Just like [`anyhow`][], any error can be cast to this type using the `?` operator.
42+
43+
For more information, see [this blog post](https://blog.yoshuawuyts.com/async-http/#error-handling).
44+
45+
#### Middleware
46+
47+
**New middleware:**
48+
```rust
49+
use surf::middleware::{Middleware, Next};
50+
use surf::{Client, Request, Response, Result};
51+
52+
#[surf::utils::async_trait]
53+
impl Middleware for Logger {
54+
async fn handle(
55+
&self,
56+
req: Request,
57+
client: Client,
58+
next: Next<'_>,
59+
) -> Result<Response> {
60+
Ok(res)
61+
}
62+
}
63+
```
64+
65+
#### RequestBuilder
66+
67+
The top-level convenience request methods, `surf::get()`, `surf::post()`, etc, now return a [`RequestBuilder`][] rather than a [`Request`][] directly.
68+
Most `RequestBuilder` functions have shorthand names: `RequestBuilder::body()` compared to `Request::set_body()`.
69+
70+
```rust
71+
let res = surf::get("http://example.org") // Now returns a `surf::RequestBuilder`!
72+
.header(a_header, a_value)
73+
.body(a_body)
74+
.await?;
75+
```
76+
77+
Overall usage was kept the same where possible and reasonable, however now a `surf::Client` must be used when using middleware.
78+
79+
```rust
80+
let client = surf::client()
81+
.with(some_middleware);
82+
83+
let res = client::post(url)
84+
.header(a_header, a_value)
85+
.body(a_body)
86+
.await?;
87+
```
88+
89+
Alternately:
90+
```rust
91+
let client = surf::client()
92+
.with(some_middleware);
93+
94+
let req = surf::post(url)
95+
.header(a_header, a_value)
96+
.body(a_body);
97+
let res = client.send(req).await?;
98+
```
99+
100+
#### Mime
101+
102+
Surf has switched from the [`mime`][] crate to [`surf::http::Mime`][] from [http-types][].
103+
104+
For more information, see [this blog post](https://blog.yoshuawuyts.com/async-http/#shared-abstractions).
105+
106+
### Additions
107+
- Switched from [`hyperium/http`][http] to [http-types][].
108+
- `surf::Request` added many methods that exist in `tide::Request`.
109+
- `surf::Response` added many methods that exist in `tide::Response`.
110+
- `surf::http`, an export of `http_types`, similar to `tide::http`.
111+
- `surf::middleware::Redirect`, a middleware to handle redirect status codes.
112+
- All conversions for `Request` and `Response` between `http_types` and `surf` now exist.
113+
- `http_types::{Error, Result}` are re-exported as `surf::{Error, Result}`.
114+
- A new `h1-client` feature enables the new [async-h1] backend.
115+
- Transcode responses from non-UTF8 charsets using the on-by-default `encoding` feature.
116+
117+
### Removals
118+
- Removed `native-client` feature flag in favor of direct `curl-client` default.
119+
- Removed `hyper-client` feature flag. (Pending re-addition, see: [#234][])
120+
- Removed `Request::body_string()`, `Request::body_json()`, etc.
121+
- This functionality is now done via [`Body`], or `Client::recv_json()`, `RequestBuilder::recv_json()`, etc.
122+
123+
### Changes
124+
- Updated to use stable [`futures`].
125+
- `wasm-client` feature is no longer automatic and must be set via cargo features.
126+
- All client feature flags are now mutually exclusive. `curl-client` is the default.
127+
- `surf::method_name` "one-off" methods now use a shared client internally if the client is `curl-client`. (Default)
128+
- `Client::with_http_client()` is now generic for any `HttpClient` rather than taking an `Arc<dyn HttpClient>`.
129+
- (The http client is still stored internally as a dynamic pointer.)
130+
- `HttpClient` has been upgraded to 6.0, removing `Clone` from the built in client backends.
131+
- `surf::Request` changed many methods to be like those in `tide::Request`.
132+
- `surf::Response` changed many methods to be like those in `tide::Response`.
133+
- Surf now uses `http-types::mime` instead of the `mime` crate.
134+
- `TryFrom<http_types::Request> for Request` is now `From<http_types::Request> for Request`.
135+
- `surf::Client` is no longer generic for `C: HttpClient`.
136+
- Middleware now receives `surf::Request` and returns `Result<surf::Response, E>`, and no longer requires a generic bound.
137+
- Middleware now uses [async-trait](https://crates.io/crates/async-trait), which is exported as `surf::utils::async_trait`.
138+
- The logger middleware is now exported as `surf::middleware::Logger`. (Note: this middleware is used by default.)
139+
- `surf::{method}()` e.g. `surf::get()` now returns a `surf::RequestBuilder` rather than a `surf::Request`.
140+
- Middleware can no longer be set for individual requests.
141+
- Instead, use a `surf::Client` and register middleware via `client.with(middleware)`.
142+
- Then, send the request from that client via `client.send()` e.g. `let res = client.send(request).await?;`.
143+
- `surf::Client` now can set a "base url" for that client via `client.set_base_url()`.
144+
- `Client` is now built on top of [`http-client`](https://github.com/http-rs/http-client).
145+
- `surf::url` has been moved to `surf::http::url`, with a `surf::Url` shortcut.
146+
147+
### Internal
148+
- Reduce copies when parsing URLs.
149+
- Now only depends on `futures_util` rather than all of `futures`.
150+
- `wasm-client` now has proper headless browser CI testing.
151+
- Use Clippy in CI.
152+
- Set up an MSRV in CI.
153+
- Stop hitting the network when running tests.
154+
155+
### Changes since 2.0.0-alpha.7
156+
- Added: `RequestBuilder` now has a `.query()` function for setting structured querystrings.
157+
- Changed: `Client::send()` and `RequestBuilder::send()` are now plain async functions and no longer return [`BoxFuture`][]s.
158+
- Changed: `surf::url` has been moved to `surf::http::url`, with a `surf::Url` shortcut.
159+
160+
[#234]: https://github.com/http-rs/surf/pull/234
161+
[`anyhow`]: https://crates.io/crates/anyhow
162+
[`async_trait`]: https://docs.rs/async-trait/0.1.41/async_trait/
163+
[`futures`]: https://doc.rust-lang.org/stable/std/future/trait.Future.html
164+
[`mime`]: https://docs.rs/mime/0.3.14/mime/index.html
165+
[`surf::http::Mime`]: https://docs.rs/surf/2.0.0/surf/http/struct.Mime.html
166+
[`surf::Error`]: https://docs.rs/surf/2.0.0/surf/struct.Error.html
167+
[`Body`]: https://docs.rs/surf/2.0.0/surf/struct.Body.html
168+
[`BoxFuture`]: https://docs.rs/futures-util/0.3.5/futures_util/future/type.BoxFuture.html
169+
[`Request`]: https://docs.rs/surf/2.0.0/surf/struct.Request.html
170+
[`RequestBuilder`]: https://docs.rs/surf/2.0.0/surf/struct.RequestBuilder.html
171+
[async-h1]: https://crates.io/crates/async-h1
172+
[http]: https://docs.rs/http/0.2.1/http
173+
[http-types]: https://github.com/http-rs/http-types
174+
[url standard]: https://crates.io/crates/url
175+
[StatusCode http]: https://docs.rs/http/0.2.1/http/status/struct.StatusCode.html
176+
[StatusCode http-types]: https://docs.rs/http-types/2.5.0/http_types/enum.StatusCode.html
177+
[Tide]: https://github.com/http-rs/tide
178+
10179
## [2.0.0-alpha.7] - 2020-09-29
11180

12181
### Fixes

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "surf"
3-
version = "2.0.0-alpha.7"
3+
version = "2.0.0"
44
license = "MIT OR Apache-2.0"
55
repository = "https://github.com/http-rs/surf"
66
documentation = "https://docs.rs/surf"

0 commit comments

Comments
 (0)