Effects
Effect is the main building block of the whole framework. It is just a function that returns a stream of events. Using its generic interface we can define API endpoints, event handlers or middlewares.
Building your own Effect
Effect :: Observable<T> -> Observable<U>HttpEffect :: Observable<HttpRequest> -> Observable<HttpEffectResponse>import { HttpEffect, HttpEffectResponse, HttpRequest } from '@marblejs/http';
import { Observable } from 'rxjs/operators';
import { mapTo } from 'rxjs/operators';
const hello$ = (req$: Observable<HttpRequest>): Observable<HttpEffectResponse> =>
req$.pipe(
mapTo({ body: 'Hello, world!' }),
);
// same as
const hello$: HttpEffect = req$ =>
req$.pipe(
mapTo({ body: 'Hello, world!' }),
);Last updated