switon / http
Controller-based HTTP boundary with request input, response shaping, lifecycle hooks, and runtime adapters for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- ext-dom: *
- psr/event-dispatcher: ^1.0
- switon/binding: ^1.0
- switon/command: ^1.0
- switon/composer-extra: ^1.0
- switon/core: ^1.0
- switon/event: ^1.0
- switon/id: ^1.0
- switon/invocation: ^1.0
- switon/invoker: ^1.0
- switon/kernel: ^1.0
- switon/principal: ^1.0
- switon/renderer: ^1.0
- switon/router: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/i18n: ^1.0
- switon/testing: ^1.0
- switon/validation: ^1.0
README
Switon's HTTP pipeline for request and response handling, attribute routing, action return normalization, request-stage filters, and transport adapters.
Highlights
- Request pipeline:
RequestHandlerInterfacedrives adjust, auth, route, validate, invoke, render, and finish stages. - Attribute routes:
#[RequestMapping]and action mappings keep routes close to controllers. - Action input binding:
RequestBody,RequestData,RequestQuery, andFiltersshape action input. - Request filters: cross-cutting filters can add request IDs, locale, CORS, and slowlog handling.
- Return normalization:
NormalizeActionReturnTransformerturns common return values into framework responses. - Response helpers:
ResponseInterfacecoversjson(),text(),raw(), andredirect(). - Runtime modes:
ServerOptionscan switch betweenauto,fpm,php, andswoole.
Installation
composer require switon/http
Quick Start
use Switon\Core\Attribute\Autowired; use Switon\Http\Controller; use Switon\Http\RequestInterface; use Switon\Http\ResponseInterface; use Switon\Routing\Attribute\GetMapping; use Switon\Routing\Attribute\RequestMapping; #[RequestMapping('/api/users')] final class UserController extends Controller { #[Autowired] protected RequestInterface $request; #[Autowired] protected ResponseInterface $response; #[GetMapping('{id}')] public function showAction(int $id): array { return [ 'id' => $id, 'locale' => $this->request->query('locale'), ]; } #[GetMapping('{id}/raw')] public function rawAction(int $id): ResponseInterface { return $this->response->json(['id' => $id]); } }
Docs: https://docs.switon.dev/latest/http
License
MIT.