From 9ff2f9d5e29f6e983f2a943d7609219671244485 Mon Sep 17 00:00:00 2001 From: Carlos Company Date: Wed, 15 Jan 2025 18:26:14 +0100 Subject: [PATCH 1/3] New: copy of the request.md file for reference --- docs/advanced/request.es.md | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 docs/advanced/request.es.md diff --git a/docs/advanced/request.es.md b/docs/advanced/request.es.md new file mode 100644 index 000000000..6f3ed73e2 --- /dev/null +++ b/docs/advanced/request.es.md @@ -0,0 +1,66 @@ +# Request + +The [`Request`](https://api.vapor.codes/vapor/documentation/vapor/request) object is passed into every [route handler](../basics/routing.md). + +```swift +app.get("hello", ":name") { req -> String in + let name = req.parameters.get("name")! + return "Hello, \(name)!" +} +``` + +It is the main window into the rest of Vapor's functionality. It contains APIs for the [request body](../basics/content.md), [query parameters](../basics/content.md#query), [logger](../basics/logging.md), [HTTP client](../basics/client.md), [Authenticator](../security/authentication.md), and more. Accessing this functionality through the request keeps computation on the correct event loop and allows it to be mocked for testing. You can even add your own [services](../advanced/services.md) to the `Request` with extensions. + +The full API documentation for `Request` can be found [here](https://api.vapor.codes/vapor/documentation/vapor/request). + +## Application + +The `Request.application` property holds a reference to the [`Application`](https://api.vapor.codes/vapor/documentation/vapor/application). This object contains all of the configuration and core functionality for the application. Most of it should only be set in `configure.swift`, before the application fully starts, and many of the lower level APIs won't be needed in most applications. One of the most useful properties is `Application.eventLoopGroup`, which can be used to get an `EventLoop` for processes that need a new one via the `any()` method. It also contains the [`Environment`](../basics/environment.md). + +## Body + +If you want direct access to the request body as a `ByteBuffer`, you can use `Request.body.data`. This can be used for streaming data from the request body to a file (though you should use the [`fileio`](../advanced/files.md) property on the request for this instead) or to another HTTP client. + +## Cookies + +While the most useful application of cookies is via built-in [sessions](../advanced/sessions.md#configuration), you can also access cookies directly via `Request.cookies`. + +```swift +app.get("my-cookie") { req -> String in + guard let cookie = req.cookies["my-cookie"] else { + throw Abort(.badRequest) + } + if let expiration = cookie.expires, expiration < Date() { + throw Abort(.badRequest) + } + return cookie.string +} +``` + +## Headers + +An `HTTPHeaders` object can be accessed at `Request.headers`. This contains all of the headers sent with the request. It can be used to access the `Content-Type` header, for example. + +```swift +app.get("json") { req -> String in + guard let contentType = req.headers.contentType, contentType == .json else { + throw Abort(.badRequest) + } + return "JSON" +} +``` +See further documentation for `HTTPHeaders` [here](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niohttp1/httpheaders). Vapor also adds several extensions to `HTTPHeaders` to make working with the most commonly-used headers easier; a list is available [here](https://api.vapor.codes/vapor/documentation/vapor/niohttp1/httpheaders#instance-properties) + +## IP Address + +The `SocketAddress` representing the client can be accessed via `Request.remoteAddress`, which may be useful for logging or rate limiting using the string representation `Request.remoteAddress.ipAddress`. It may not accurately represent the client's IP address if the application is behind a reverse proxy. + +```swift +app.get("ip") { req -> String in + return req.remoteAddress.ipAddress +} +``` + +See further documentation for `SocketAddress` [here](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niocore/socketaddress). + + From e7ee7fa79d8d6bf302c77034312b72d8cc657838 Mon Sep 17 00:00:00 2001 From: Carlos Company Date: Wed, 15 Jan 2025 18:34:08 +0100 Subject: [PATCH 2/3] NEW: translation EN (current request.md file) to ES (new request.es.md file) --- docs/advanced/request.es.md | 31 +++++++++++++++---------------- docs/advanced/request.md | 3 +-- mkdocs.yml | 1 + 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/docs/advanced/request.es.md b/docs/advanced/request.es.md index 6f3ed73e2..9e35c0621 100644 --- a/docs/advanced/request.es.md +++ b/docs/advanced/request.es.md @@ -1,6 +1,6 @@ -# Request +# Solicitud (Request) -The [`Request`](https://api.vapor.codes/vapor/documentation/vapor/request) object is passed into every [route handler](../basics/routing.md). +El objeto [`Request`](https://api.vapor.codes/vapor/documentation/vapor/request) (solicitud) se pasa a cada [controlador de ruta](../basics/routing.md). ```swift app.get("hello", ":name") { req -> String in @@ -9,21 +9,21 @@ app.get("hello", ":name") { req -> String in } ``` -It is the main window into the rest of Vapor's functionality. It contains APIs for the [request body](../basics/content.md), [query parameters](../basics/content.md#query), [logger](../basics/logging.md), [HTTP client](../basics/client.md), [Authenticator](../security/authentication.md), and more. Accessing this functionality through the request keeps computation on the correct event loop and allows it to be mocked for testing. You can even add your own [services](../advanced/services.md) to the `Request` with extensions. +Es la ventana principal al resto de la funcionalidad de Vapor. Contiene APIs para el [cuerpo de la solicitud](../basics/content.md), [parámetros de consulta](../basics/content.md#query), [logger](../basics/logging.md), [cliente HTTP](../basics/client.md), [Autenticador](../security/authentication.md) y más. Accediendo a esta funcionalidad a través de la solicitud, se mantiene el cálculo en el bucle de eventos correcto y permite simularla para realizar pruebas. Incluso puedes añadir tus propios [servicios](../advanced/services.md) a la `Request` con extensiones. -The full API documentation for `Request` can be found [here](https://api.vapor.codes/vapor/documentation/vapor/request). +La documentación completa de la API para `Request` se puede encontrar [aquí](https://api.vapor.codes/vapor/documentation/vapor/request). -## Application +## Aplicación -The `Request.application` property holds a reference to the [`Application`](https://api.vapor.codes/vapor/documentation/vapor/application). This object contains all of the configuration and core functionality for the application. Most of it should only be set in `configure.swift`, before the application fully starts, and many of the lower level APIs won't be needed in most applications. One of the most useful properties is `Application.eventLoopGroup`, which can be used to get an `EventLoop` for processes that need a new one via the `any()` method. It also contains the [`Environment`](../basics/environment.md). +La propiedad `Request.application` contiene una referencia a la [`Aplicación`](https://api.vapor.codes/vapor/documentation/vapor/application). Este objeto contiene toda la configuración y la funcionalidad central de la aplicación. La mayor parte solo se debe configurar en `configure.swift`, antes de que la aplicación se inicie por completo, y muchas de las APIs de bajo nivel no serán necesarias en la mayoría de las aplicaciones. Una de las propiedades más útiles es `Application.eventLoopGroup`, que se puede utilizar para obtener un `EventLoop` para los procesos que necesitan uno nuevo a través del método `any()`. También contiene el [`Entorno`](../basics/environment.md). ## Body -If you want direct access to the request body as a `ByteBuffer`, you can use `Request.body.data`. This can be used for streaming data from the request body to a file (though you should use the [`fileio`](../advanced/files.md) property on the request for this instead) or to another HTTP client. +Si quieres acceder directamente al cuerpo de la solicitud como un `ByteBuffer`, puedes utilizar `Request.body.data`. Esto puede utilizarse para transmitir datos desde el cuerpo de la solicitud a un archivo (aunque para esto deberías utilizar la propiedad [`fileio`](../advanced/files.md) en la solicitud) o a otro cliente HTTP. ## Cookies -While the most useful application of cookies is via built-in [sessions](../advanced/sessions.md#configuration), you can also access cookies directly via `Request.cookies`. +Aunque la aplicación más útil de las cookies es a través de las [sesiones](../advanced/sessions.md#configuration) integradas, también puedes acceder a las cookies directamente a través de `Request.cookies`. ```swift app.get("my-cookie") { req -> String in @@ -37,9 +37,9 @@ app.get("my-cookie") { req -> String in } ``` -## Headers +## Cabeceras -An `HTTPHeaders` object can be accessed at `Request.headers`. This contains all of the headers sent with the request. It can be used to access the `Content-Type` header, for example. +Se puede acceder a un objeto `HTTPHeaders` en `Request.headers`. Contiene todas las cabeceras enviadas con la solicitud. Se puede utilizar para acceder a la cabecera `Content-Type`, por ejemplo. ```swift app.get("json") { req -> String in @@ -49,11 +49,12 @@ app.get("json") { req -> String in return "JSON" } ``` -See further documentation for `HTTPHeaders` [here](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niohttp1/httpheaders). Vapor also adds several extensions to `HTTPHeaders` to make working with the most commonly-used headers easier; a list is available [here](https://api.vapor.codes/vapor/documentation/vapor/niohttp1/httpheaders#instance-properties) -## IP Address +Consulta más documentación sobre `HTTPHeaders` [aquí](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niohttp1/httpheaders). Vapor también añade varias extensiones a `HTTPHeaders` para facilitar el trabajo con las cabeceras más utilizadas; la lista está disponible [aquí](https://api.vapor.codes/vapor/documentation/vapor/niohttp1/httpheaders#instance-properties) -The `SocketAddress` representing the client can be accessed via `Request.remoteAddress`, which may be useful for logging or rate limiting using the string representation `Request.remoteAddress.ipAddress`. It may not accurately represent the client's IP address if the application is behind a reverse proxy. +## Dirección IP + +Puedes acceder a la `SocketAddress` que representa al cliente a través de `Request.remoteAddress`, que puede ser útil para el registro o la limitación de velocidad utilizando la representación de la cadena `Request.remoteAddress.ipAddress`. Puede que no represente con exactitud la dirección IP del cliente si la aplicación está detrás de un proxy inverso. ```swift app.get("ip") { req -> String in @@ -61,6 +62,4 @@ app.get("ip") { req -> String in } ``` -See further documentation for `SocketAddress` [here](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niocore/socketaddress). - - +Consulta más documentación sobre `SocketAddress` [aquí](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niocore/socketaddress). diff --git a/docs/advanced/request.md b/docs/advanced/request.md index 6f3ed73e2..15ef79d0d 100644 --- a/docs/advanced/request.md +++ b/docs/advanced/request.md @@ -49,6 +49,7 @@ app.get("json") { req -> String in return "JSON" } ``` + See further documentation for `HTTPHeaders` [here](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niohttp1/httpheaders). Vapor also adds several extensions to `HTTPHeaders` to make working with the most commonly-used headers easier; a list is available [here](https://api.vapor.codes/vapor/documentation/vapor/niohttp1/httpheaders#instance-properties) ## IP Address @@ -62,5 +63,3 @@ app.get("ip") { req -> String in ``` See further documentation for `SocketAddress` [here](https://swiftpackageindex.com/apple/swift-nio/2.56.0/documentation/niocore/socketaddress). - - diff --git a/mkdocs.yml b/mkdocs.yml index 64e83cd19..7dd47238e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -365,6 +365,7 @@ plugins: Redis: Redis Relations: Relaciones Release Notes: Notas de Versiones + Request: Solicitud Routing: Routing Schema: Esquema Security: Seguridad From d8d16cbe6039bd534684adcf60db5f92eb92fd4c Mon Sep 17 00:00:00 2001 From: TheHandyOwl <24987271+TheHandyOwl@users.noreply.github.com> Date: Wed, 15 Jan 2025 23:19:59 +0100 Subject: [PATCH 3/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ale Mohamad ⌘ --- docs/advanced/request.es.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/advanced/request.es.md b/docs/advanced/request.es.md index 9e35c0621..abbd96fc5 100644 --- a/docs/advanced/request.es.md +++ b/docs/advanced/request.es.md @@ -15,7 +15,7 @@ La documentación completa de la API para `Request` se puede encontrar [aquí](h ## Aplicación -La propiedad `Request.application` contiene una referencia a la [`Aplicación`](https://api.vapor.codes/vapor/documentation/vapor/application). Este objeto contiene toda la configuración y la funcionalidad central de la aplicación. La mayor parte solo se debe configurar en `configure.swift`, antes de que la aplicación se inicie por completo, y muchas de las APIs de bajo nivel no serán necesarias en la mayoría de las aplicaciones. Una de las propiedades más útiles es `Application.eventLoopGroup`, que se puede utilizar para obtener un `EventLoop` para los procesos que necesitan uno nuevo a través del método `any()`. También contiene el [`Entorno`](../basics/environment.md). +La propiedad `Request.application` contiene una referencia a [`Application`](https://api.vapor.codes/vapor/documentation/vapor/application). Este objeto contiene toda la configuración y la funcionalidad central de la aplicación. La mayor parte solo se debe configurar en `configure.swift`, antes de que la aplicación se inicie por completo, y muchas de las APIs de bajo nivel no serán necesarias en la mayoría de las aplicaciones. Una de las propiedades más útiles es `Application.eventLoopGroup`, que se puede utilizar para obtener un `EventLoop` para los procesos que necesitan uno nuevo a través del método `any()`. También contiene [`Environment`](../basics/environment.md). ## Body @@ -39,7 +39,7 @@ app.get("my-cookie") { req -> String in ## Cabeceras -Se puede acceder a un objeto `HTTPHeaders` en `Request.headers`. Contiene todas las cabeceras enviadas con la solicitud. Se puede utilizar para acceder a la cabecera `Content-Type`, por ejemplo. +Se puede acceder a un objeto `HTTPHeaders` en `Request.headers`. Contiene todas las cabeceras (headers) enviadas con la solicitud. Se puede utilizar para acceder a la cabecera `Content-Type`, por ejemplo. ```swift app.get("json") { req -> String in @@ -54,7 +54,7 @@ Consulta más documentación sobre `HTTPHeaders` [aquí](https://swiftpackageind ## Dirección IP -Puedes acceder a la `SocketAddress` que representa al cliente a través de `Request.remoteAddress`, que puede ser útil para el registro o la limitación de velocidad utilizando la representación de la cadena `Request.remoteAddress.ipAddress`. Puede que no represente con exactitud la dirección IP del cliente si la aplicación está detrás de un proxy inverso. +Puedes acceder a la `SocketAddress` que representa al cliente a través de `Request.remoteAddress`, que puede ser útil para el registro o la limitación de velocidad utilizando la representación de la cadena `Request.remoteAddress.ipAddress`. Puede que no represente con exactitud la dirección IP del cliente si la aplicación está detrás de un reverse proxy. ```swift app.get("ip") { req -> String in