mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
update migration
This commit is contained in:
parent
e55be4dba6
commit
7801fcb993
@ -1,5 +1,10 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Added async io `TestBuffer` for testing.
|
||||||
|
|
||||||
|
|
||||||
## [1.0.0-alpha.4] - 2019-04-08
|
## [1.0.0-alpha.4] - 2019-04-08
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
112
MIGRATION.md
112
MIGRATION.md
@ -1,5 +1,65 @@
|
|||||||
## 1.0
|
## 1.0
|
||||||
|
|
||||||
|
* Resource registration. 1.0 version uses generalized resource
|
||||||
|
registration via `.service()` method.
|
||||||
|
|
||||||
|
instead of
|
||||||
|
|
||||||
|
```rust
|
||||||
|
App.new().resource("/welcome", |r| r.f(welcome))
|
||||||
|
```
|
||||||
|
|
||||||
|
use App's or Scope's `.service()` method. `.service()` method accepts
|
||||||
|
object that implements `HttpServiceFactory` trait. By default
|
||||||
|
actix-web provides `Resource` and `Scope` services.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
App.new().service(
|
||||||
|
web::resource("/welcome")
|
||||||
|
.route(web::get().to(welcome))
|
||||||
|
.route(web::post().to(post_handler))
|
||||||
|
```
|
||||||
|
|
||||||
|
* Scope registration.
|
||||||
|
|
||||||
|
instead of
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let app = App::new().scope("/{project_id}", |scope| {
|
||||||
|
scope
|
||||||
|
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
|
.resource("/path2", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
|
.resource("/path3", |r| r.f(|_| HttpResponse::MethodNotAllowed()))
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
use `.service()` for registration and `web::scope()` as scope object factory.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let app = App::new().service(
|
||||||
|
web::scope("/{project_id}")
|
||||||
|
.service(web::resource("/path1").to(|| HttpResponse::Ok()))
|
||||||
|
.service(web::resource("/path2").to(|| HttpResponse::Ok()))
|
||||||
|
.service(web::resource("/path3").to(|| HttpResponse::MethodNotAllowed()))
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
* `.f()`, `.a()` and `.h()` handler registration methods have been removed.
|
||||||
|
Use `.to()` for handlers and `.to_async()` for async handlers. Handler function
|
||||||
|
must use extractors.
|
||||||
|
|
||||||
|
instead of
|
||||||
|
|
||||||
|
```rust
|
||||||
|
App.new().resource("/welcome", |r| r.f(welcome))
|
||||||
|
```
|
||||||
|
|
||||||
|
use App's `to()` or `to_async()` methods
|
||||||
|
|
||||||
|
```rust
|
||||||
|
App.new().service(web::resource("/welcome").to(welcome))
|
||||||
|
```
|
||||||
|
|
||||||
* `State` is now `Data`. You register Data during the App initialization process
|
* `State` is now `Data`. You register Data during the App initialization process
|
||||||
and then access it from handlers either using a Data extractor or using
|
and then access it from handlers either using a Data extractor or using
|
||||||
HttpRequest's api.
|
HttpRequest's api.
|
||||||
@ -52,6 +112,58 @@ HttpRequest's api.
|
|||||||
.. simply omit AsyncResponder and the corresponding responder() finish method
|
.. simply omit AsyncResponder and the corresponding responder() finish method
|
||||||
|
|
||||||
|
|
||||||
|
* Middleware
|
||||||
|
|
||||||
|
instead of
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let app = App::new()
|
||||||
|
.middleware(middleware::Logger::default())
|
||||||
|
```
|
||||||
|
|
||||||
|
use `.wrap()` method
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let app = App::new()
|
||||||
|
.wrap(middleware::Logger::default())
|
||||||
|
.route("/index.html", web::get().to(index));
|
||||||
|
```
|
||||||
|
|
||||||
|
* `HttpRequest::body()`, `HttpRequest::urlencoded()`, `HttpRequest::json()`, `HttpRequest::multipart()`
|
||||||
|
method have been removed. Use `Bytes`, `String`, `Form`, `Json`, `Multipart` extractors instead.
|
||||||
|
|
||||||
|
instead if
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn index(req: &HttpRequest) -> Responder {
|
||||||
|
req.body()
|
||||||
|
.and_then(|body| {
|
||||||
|
...
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn index(body: Bytes) -> Responder {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* StaticFiles and NamedFile has been move to separate create.
|
||||||
|
|
||||||
|
instead of `use actix_web::fs::StaticFile`
|
||||||
|
|
||||||
|
use `use actix_files::Files`
|
||||||
|
|
||||||
|
instead of `use actix_web::fs::Namedfile`
|
||||||
|
|
||||||
|
use `use actix_files::NamedFile`
|
||||||
|
|
||||||
|
* Multipart has been move to separate create.
|
||||||
|
|
||||||
|
instead of `use actix_web::multipart::Multipart`
|
||||||
|
|
||||||
|
use `use actix_multipart::Multipart`
|
||||||
|
|
||||||
|
|
||||||
## 0.7.15
|
## 0.7.15
|
||||||
|
|
||||||
|
@ -32,8 +32,9 @@ pub(crate) trait DataFactoryResult {
|
|||||||
/// an application instance. Http server constructs an application
|
/// an application instance. Http server constructs an application
|
||||||
/// instance for each thread, thus application data must be constructed
|
/// instance for each thread, thus application data must be constructed
|
||||||
/// multiple times. If you want to share data between different
|
/// multiple times. If you want to share data between different
|
||||||
/// threads, a shared object should be used, e.g. `Arc`. Application
|
/// threads, a shareable object should be used, e.g. `Send + Sync`. Application
|
||||||
/// data does not need to be `Send` or `Sync`.
|
/// data does not need to be `Send` or `Sync`. Internally `Data` instance
|
||||||
|
/// uses `Arc`.
|
||||||
///
|
///
|
||||||
/// If route data is not set for a handler, using `Data<T>` extractor would
|
/// If route data is not set for a handler, using `Data<T>` extractor would
|
||||||
/// cause *Internal Server Error* response.
|
/// cause *Internal Server Error* response.
|
||||||
|
Loading…
Reference in New Issue
Block a user