#[RestController] attribute transforms an ordinary PHP class into a fully managed HTTP handler. The framework discovers annotated classes automatically through namespace scanning, wires their dependencies, routes incoming requests to the correct method, and serialises the return value into an HTTP response — all without any XML, YAML, or routing-file configuration.
Registering a Controller
Apply#[RestController] at the class level to register the class as a REST endpoint handler. The class must be concrete (non-abstract), and its namespace must fall within one of the component-scan packages declared in your application configuration.
UserController.php
Injecting Dependencies
Inject services, repositories, and other beans into your controller with#[Autowired]. Winter Boot resolves and injects the dependency at startup, so there is no manual container look-up at runtime.
UserController.php
Reading the Request
Add anHttpRequest parameter to any handler method and Winter Boot hands you the current request. Use it to read anything the parameter annotations (#[PathVariable], #[RequestParam], #[RequestBody]) do not cover — headers, cookies, the raw body, or details about the caller.
UserController.php
Caller and server details
These getters describe who called and where the request landed — the client address for localhost checks or logging, the server address for multi-homed hosts, and timing info. They returnnull when the runtime did not provide a value.
Always read these from
HttpRequest, never from $_SERVER. Under Swoole many requests share one process, so $_SERVER can hold another request’s values — the getters always return the current request’s own data.Return Types
Controller methods can return three types of value. Winter Boot inspects the return value and sets the appropriateContent-Type header automatically.
ResponseEntity Builder API
ResponseEntity (namespace dev\winterframework\web\http\ResponseEntity) provides static factory methods to start a response, followed by fluent builder calls to attach a body or headers.
ResponseEntity factory methods
ResponseEntity factory methods
ResponseEntity builder methods
ResponseEntity builder methods
Setting cookies
withCookie() sends a cookie with the response. Only name is required — everything else has a safe default:
Set-Cookie header. Read the cookies a request carried with HttpRequest::getCookie($name) (see Reading the Request).
Complete CRUD Example
The controller below brings together every common pattern:#[Autowired] injection, all five HTTP method annotations, #[PathVariable], #[RequestBody], #[RequestParam], and both array and ResponseEntity return types.
UserController.php
Testing with curl
Error Handling
When an unhandled error or exception occurs, Winter Boot delegates to anErrorController implementation. The ErrorController interface lives in dev\winterframework\core\web\error\ErrorController and exposes a single method:
errorController using either of the two approaches below.
- @Component
- @Bean
MyErrorController.php