Skip to content

Commit

Permalink
fix doc error
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Aug 16, 2024
1 parent 736caf3 commit 882a1e8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
12 changes: 6 additions & 6 deletions docs/book/core/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The salvo framework provides built-in request parameter extractors. These extrac
#### JsonBody
Used to extract JSON data from the request body and deserialize it into a specified type.

``` rust
```rust
#[handler]
async fn create_user(json: JsonBody<User>) -> String {
let user = json.into_inner();
Expand All @@ -92,7 +92,7 @@ async fn create_user(json: JsonBody<User>) -> String {
#### FormBody
Extracts form data from the request body and deserializes it into a specified type.

``` rust
```rust
#[handler]
async fn update_user(form: FormBody<User>) -> String {
let user = form.into_inner();
Expand All @@ -102,7 +102,7 @@ async fn update_user(form: FormBody<User>) -> String {
#### CookieParam
Extracts a specific value from the request's Cookie.

``` rust
```rust
//When the second parameter is true, if the value doesn't exist,
//into_inner() will panic. When it's false, the into_inner()
//method returns Option<T>.
Expand All @@ -114,7 +114,7 @@ fn get_user_from_cookie(user_id: CookieParam<i64,true>) -> String {
#### HeaderParam
Extracts a specific value from the request headers.

``` rust
```rust
#[handler]
fn get_user_from_header(user_id: HeaderParam<i64,true>) -> String {
format!("User ID retrieved from header: {}", user_id.into_inner())
Expand All @@ -123,7 +123,7 @@ fn get_user_from_header(user_id: HeaderParam<i64,true>) -> String {
#### PathParam
Extracts parameters from the URL path.

``` rust
```rust
#[handler]
fn get_user(id: PathParam<i64>) -> String {
format!("User ID retrieved from path: {}", id.into_inner())
Expand All @@ -132,7 +132,7 @@ fn get_user(id: PathParam<i64>) -> String {
#### QueryParam
Extracts parameters from the URL query string.

``` rust
```rust
#[handler]
fn search_user(id: QueryParam<i64,true>) -> String {
format!("Searching for user with ID: {}", id.into_inner())
Expand Down
2 changes: 1 addition & 1 deletion docs/book/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ There are many ways to write function handler.

- You can omit function arguments if they are not used, like `_req`, `_depot`, `_ctrl` in this example:

``` rust
```rust
#[handler]
async fn hello(res: &mut Response) {
res.render("Hello world");
Expand Down
16 changes: 12 additions & 4 deletions docs/es/book/core/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,29 @@ El marco incluye extractores de parámetros de solicitud. Estos extractores pued
#### JsonBody
Se utiliza para extraer datos JSON del cuerpo de la solicitud y deserializarlos en un tipo específico.

rust
```rust
#[handler]
async fn create_user(json: JsonBody<User>) -> String {
let user = json.into_inner();
format!("Se ha creado un usuario con ID: {}", user.id)
}
```

#### FormBody
Extrae datos de formulario del cuerpo de la solicitud y los deserializa en un tipo específico.

rust
```rust
#[handler]
async fn update_user(form: FormBody<User>) -> String {
let user = form.into_inner();
format!("Se ha actualizado el usuario con ID: {}", user.id)
}
```

#### CookieParam
Extrae un valor específico de la Cookie de la solicitud.

``` rust
```rust
//Cuando el segundo parámetro es true,
//si el valor no existe, into_inner() provocará un pánico.
//Cuando es false, el método into_inner() devuelve Option<T>.
Expand All @@ -110,6 +114,7 @@ fn get_user_from_cookie(user_id: CookieParam<i64,true>) -> String {
format!("ID de usuario obtenido de la Cookie: {}", user_id.into_inner())
}
```

#### HeaderParam
Extrae un valor específico de los encabezados de la solicitud.

Expand All @@ -119,6 +124,7 @@ fn get_user_from_header(user_id: HeaderParam<i64,true>) -> String {
format!("ID de usuario obtenido del encabezado: {}", user_id.into_inner())
}
```

#### PathParam
Extrae parámetros de la ruta URL.

Expand All @@ -128,15 +134,17 @@ fn get_user(id: PathParam<i64>) -> String {
format!("ID de usuario obtenido de la ruta: {}", id.into_inner())
}
```

#### QueryParam
Extrae parámetros de la cadena de consulta URL.

``` rust
```rust
#[handler]
fn search_user(id: QueryParam<i64,true>) -> String {
format!("Buscando usuario con ID: {}", id.into_inner())
}
```

### Uso avanzado

Multiples tipos de datos pueden ser mezclados en un tipo de dato específico. Puedes definir un tipo de dato personalizado como el que se encuentra a continuación:
Expand Down
2 changes: 1 addition & 1 deletion docs/es/book/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Existen muchas formas para escribir una función del tipo controlador.

- Puedes omitir los argumentos como `_req`, `_depot`, `_ctrl` si no los usas como se ve en el siguiente ejemplo:

``` rust
```rust
#[handler]
async fn hello(res: &mut Response) {
res.render("Hello world");
Expand Down
6 changes: 3 additions & 3 deletions docs/zh-hans/book/core/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ assert_eq!(user.ids, vec![123, 234]);
#### JsonBody
用于从请求体中提取 JSON 数据并反序列化为指定类型。

``` rust
```rust
#[handler]
async fn create_user(json: JsonBody<User>) -> String {
let user = json.into_inner();
Expand All @@ -97,7 +97,7 @@ async fn create_user(json: JsonBody<User>) -> String {
#### FormBody
从请求体中提取表单数据并反序列化为指定类型。

``` rust
```rust
#[handler]
async fn update_user(form: FormBody<User>) -> String {
let user = form.into_inner();
Expand Down Expand Up @@ -137,7 +137,7 @@ fn get_user(id: PathParam<i64>) -> String {
#### QueryParam
从 URL 查询字符串中提取参数。

``` rust
```rust
#[handler]
fn search_user(id: QueryParam<i64,true>) -> String {
format!("正在搜索ID为 {} 的用户", id.into_inner())
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-hans/book/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tracing-subscriber = "0.3"

- 您可以省略函数中某些用不着的参数, 比如这里面的 `_req`, `_depot`, `_ctrl` 都没有被使用, 可以直接不写:

``` rust
```rust
#[handler]
async fn hello(res: &mut Response) {
res.render("Hello world");
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-hant/book/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tracing-subscriber = "0.3"

- 您可以省略函數中某些用不着的參數, 比如這裏面的 `_req`, `_depot`, `_ctrl` 都沒有被使用, 可以直接不寫:

``` rust
```rust
#[handler]
async fn hello(res: &mut Response) {
res.render("Hello world");
Expand Down

0 comments on commit 882a1e8

Please sign in to comment.