Observable return types allow NestJS route handlers to return RxJS Observable streams. The framework automatically subscribes to the Observable and resolves the final emitted value once the stream completes.
Usage
import { Observable } from 'rxjs';
import { of } from 'rxjs';
@Get()
findAll(): Observable<any[]> {
return of([]);
}How it works
- Nest subscribes to the Observable internally
- The final emitted value is sent as the HTTP response
- Stream completion triggers response sending
- Errors are handled by Nest’s exception filters
Supported return types
NestJS route handlers support multiple async patterns:
- Promises
- RxJS Observables
- Synchronous values
This flexibility allows integration with various async data sources and reactive programming patterns.