You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A core pattern of any web application is to access data from the current request. You may do so by injecting {`Tempest\Router\Request`} to a controller action. This class provides access to the request's body, query parameters, method, and other attributes through dedicated class properties.
178
+
A core pattern of any web application is to access data from the current request. You may do so by injecting {`Tempest\Http\Request`} to a controller action. This class provides access to the request's body, query parameters, method, and other attributes through dedicated class properties.
179
179
180
180
### Using request classes
181
181
182
182
In most situations, the data you expect to receive from a request is structured. You expect clients to send specific values, and you want them to follow specific rules.
183
183
184
184
The idiomatic way to achieve this is by using request classes. They are classes with public properties that correspond to the data you want to retrieve from the request. Tempest will automatically validate these properties using PHP's type system, in addition to optional [validation attributes](../2-features/06-validation) if needed.
185
185
186
-
A request class must implement {`Tempest\Router\Request`} and should use the {`Tempest\Router\IsRequest`} trait, which provides the default implementation.
186
+
A request class must implement {`Tempest\Http\Request`} and should use the {`Tempest\Http\IsRequest`} trait, which provides the default implementation.
187
187
188
188
```php app/RegisterAirportRequest.php
189
-
use Tempest\Router\Request;
190
-
use Tempest\Router\IsRequest;
189
+
use Tempest\Http\Request;
190
+
use Tempest\Http\IsRequest;
191
191
use Tempest\Validation\Rules\Length;
192
192
193
193
final class RegisterAirportRequest implements Request
@@ -211,7 +211,7 @@ Once you have created a request class, you may simply inject it into a controlle
211
211
212
212
```php app/AirportController.php
213
213
use Tempest\Router\Post;
214
-
use Tempest\Router\Responses\Redirect;
214
+
use Tempest\Http\Responses\Redirect;
215
215
use function Tempest\map;
216
216
use function Tempest\uri;
217
217
@@ -237,7 +237,7 @@ For simpler use cases, you may simply retrieve a value from the body or the quer
237
237
238
238
```php app/AircraftController.php
239
239
use Tempest\Router\Get;
240
-
use Tempest\Router\Request;
240
+
use Tempest\Http\Request;
241
241
242
242
final readonly class AircraftController
243
243
{
@@ -256,7 +256,7 @@ Middleware can be applied to handle tasks in between receiving a request and sen
256
256
257
257
```php app/ReceiveInteractionController.php
258
258
use Tempest\Router\Get;
259
-
use Tempest\Router\Response;
259
+
use Tempest\Http\Response;
260
260
261
261
final readonly class ReceiveInteractionController
262
262
{
@@ -275,8 +275,8 @@ The middleware class must be an invokable class that implements the {`Tempest\Ro
275
275
```php
276
276
use Tempest\Router\HttpMiddleware;
277
277
use Tempest\Router\HttpMiddlewareCallable;
278
-
use Tempest\Router\Request;
279
-
use Tempest\Router\Response;
278
+
use Tempest\Http\Request;
279
+
use Tempest\Http\Response;
280
280
use Tempest\Discovery\SkipDiscovery;
281
281
use Tempest\Core\Priority;
282
282
@@ -352,7 +352,7 @@ Tempest has a powerful templating system inspired by modern front-end frameworks
352
352
353
353
### Using built-in response classes
354
354
355
-
Tempest provides several classes, all implementing the {`Tempest\Router\Response`} interface, mostly named after HTTP statuses.
355
+
Tempest provides several classes, all implementing the {`Tempest\Http\Response`} interface, mostly named after HTTP statuses.
356
356
357
357
-`{php}Ok` — the 200 response. Accepts an optional body.
358
358
-`{php}Created` — the 201 response. Accepts an optional body.
@@ -368,9 +368,9 @@ The following example conditionnally returns a `Redirect`, otherwise letting the
368
368
369
369
```php app/FlightPlanController.php
370
370
use Tempest\Router\Get;
371
-
use Tempest\Router\Responses\Download;
372
-
use Tempest\Router\Responses\Redirect;
373
-
use Tempest\Router\Response;
371
+
use Tempest\Http\Responses\Download;
372
+
use Tempest\Http\Responses\Redirect;
373
+
use Tempest\Http\Response;
374
374
375
375
final readonly class FlightPlanController
376
376
{
@@ -392,14 +392,14 @@ final readonly class FlightPlanController
392
392
393
393
It might happen that you need to dynamically compute the response's status code, and would rather not use a condition to send the corresponding response object.
394
394
395
-
You may then return an instance of {`Tempest\Router\GenericResponse`}, specifying the status code and an optional body.
395
+
You may then return an instance of {`Tempest\Http\GenericResponse`}, specifying the status code and an optional body.
396
396
397
397
```php app/CreateFlightController.php
398
398
use Tempest\Router\Get;
399
-
use Tempest\Router\Responses\Download;
400
-
use Tempest\Router\Responses\Redirect;
401
-
use Tempest\Router\GenericResponse;
402
-
use Tempest\Router\Response;
399
+
use Tempest\Http\Responses\Download;
400
+
use Tempest\Http\Responses\Redirect;
401
+
use Tempest\Http\GenericResponse;
402
+
use Tempest\Http\Response;
403
403
404
404
final readonly class CreateFlightController
405
405
{
@@ -421,12 +421,12 @@ final readonly class CreateFlightController
421
421
422
422
There are situations where you might send the same kind of response in a lot of places, or you might want to have a proper API for sending a structured response.
423
423
424
-
You may create your own response class by implementing {`Tempest\Router\Response`}, which default implementation is provided by the {`Tempest\Router\IsResponse`} trait:
424
+
You may create your own response class by implementing {`Tempest\Http\Response`}, which default implementation is provided by the {`Tempest\Http\IsResponse`} trait:
425
425
426
426
```php app/AircraftRegistered.php
427
-
use Tempest\Router\IsResponse;
428
-
use Tempest\Router\Response;
429
-
use Tempest\Router\Status;
427
+
use Tempest\Http\IsResponse;
428
+
use Tempest\Http\Response;
429
+
use Tempest\Http\Status;
430
430
431
431
final class AircraftRegistered implements Response
432
432
{
@@ -452,8 +452,8 @@ However, you may override the content type manually by specifying the `setConten
452
452
```php app/JsonController.php
453
453
use Tempest\Router\Get;
454
454
use Tempest\Router\ContentType;
455
-
use Tempest\Router\Response;
456
-
use Tempest\Router\Responses\Ok;
455
+
use Tempest\Http\Response;
456
+
use Tempest\Http\Responses\Ok;
457
457
458
458
final readonly class JsonController
459
459
{
@@ -530,8 +530,8 @@ Tempest provides a way to perform that task after the response has been sent, so
0 commit comments