#[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
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
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