### Installing @marblejs/messaging Module (npm) Source: https://github.com/marblejs/marble/blob/master/packages/messaging/README.md Installs the @marblejs/messaging module using npm. Requires @marblejs/core, rxjs, and fp-ts to be already installed. ```Shell $ npm i @marblejs/messaging ``` -------------------------------- ### Installing @marblejs/http with npm Source: https://github.com/marblejs/marble/blob/master/packages/http/README.md This command installs the @marblejs/http module using npm. It requires @marblejs/core, rxjs, and fp-ts to be installed separately. ```shell $ npm i @marblejs/http ``` -------------------------------- ### Installing @marblejs/middleware-body with npm Source: https://github.com/marblejs/marble/blob/master/packages/middleware-body/README.md Command to install the @marblejs/middleware-body package using the npm package manager. This middleware requires @marblejs/core and @marblejs/http to be installed as prerequisites. ```bash npm i @marblejs/middleware-body ``` -------------------------------- ### Installing @marblejs/middleware-io with npm Source: https://github.com/marblejs/marble/blob/master/packages/middleware-io/README.md Installs the `@marblejs/middleware-io` package using npm. This middleware requires `@marblejs/core` to be installed separately. ```Shell $ npm i @marblejs/middleware-io ``` -------------------------------- ### Installing @marblejs/testing module (npm) Source: https://github.com/marblejs/marble/blob/master/packages/testing/README.md Installs the @marblejs/testing package using npm. This module requires @marblejs/core, @marblejs/http, @marblejs/messaging, @marblejs/websockets, fp-ts, and rxjs as peer dependencies. ```shell $ npm i @marblejs/testing ``` -------------------------------- ### Install @marblejs/websockets via npm Source: https://github.com/marblejs/marble/blob/master/packages/websockets/README.md Installs the @marblejs/websockets module using npm. This module requires @marblejs/core, rxjs, and fp-ts to be installed as peer dependencies. ```Shell $ npm i @marblejs/websockets ``` -------------------------------- ### Installing @marblejs/middleware-logger (npm) Source: https://github.com/marblejs/marble/blob/master/packages/middleware-logger/README.md Installs the @marblejs/middleware-logger package using npm. Requires @marblejs/core and @marblejs/http to be pre-installed. ```Shell $ npm i @marblejs/middleware-logger ``` -------------------------------- ### Using @marblejs/middleware-multipart with Custom Stream Handler (TypeScript) Source: https://github.com/marblejs/marble/blob/master/packages/middleware-multipart/README.md This example shows how to use the `multipart$()` middleware with a custom `stream` handler. This allows intercepting incoming files and processing them differently, such as streaming them directly to the filesystem. It also demonstrates configuring options like `maxFileCount` and specifying allowed `files` by field name. ```typescript import { multipart$, StreamHandler } from '@marblejs/middleware-multipart'; const stream: StreamHandler = ({ file, fieldname }) => { const destination = // ... return of({ destination }); }; const effect$ = r.pipe( r.matchPath('/'), r.matchType('POST'), r.useEffect(req$ => req$.pipe( multipart$({ stream, maxFileCount: 1, files: ['image_1'] }), map(req => ({ body: { files: req.files['image_1'], // file information body: req.body // all incoming body fields }})) ))); ``` -------------------------------- ### Using bodyParser$ middleware in Marble.js httpListener Source: https://github.com/marblejs/marble/blob/master/packages/middleware-body/README.md Demonstrates how to import the bodyParser$ middleware and include it in the middlewares array when configuring a Marble.js httpListener. This integrates the body parsing functionality into the HTTP server. ```typescript import { bodyParser$ } from '@marblejs/middleware-body'; const middlewares = [ bodyParser$(), // ... ]; const effects = [ // ... ]; export const app = httpListener({ middlewares, effects }); ``` -------------------------------- ### Applying CORS Middleware in Marble.js Source: https://github.com/marblejs/marble/blob/master/packages/middleware-cors/README.md This snippet demonstrates how to integrate the `cors$` middleware into a Marble.js application's `httpListener`. It shows common configuration options like `origin`, `methods`, `optionsSuccessStatus`, `allowHeaders`, and `maxAge` to allow incoming requests with specific settings. ```typescript import { cors$ } from '@marblejs/middleware-cors'; const middlewares = [ logger$, cors$({ origin: '*', methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], optionsSuccessStatus: 204, allowHeaders: '*', maxAge: 3600, }) ]; const effects = [ endpoint1$, endpoint2$, ... ]; const app = httpListener({ middlewares, effects }); ``` -------------------------------- ### Using logger$ Middleware in Marble.js Application (TypeScript) Source: https://github.com/marblejs/marble/blob/master/packages/middleware-logger/README.md Demonstrates how to integrate the logger$ middleware into a Marble.js HTTP application by adding it to the middlewares array of the httpListener configuration. ```TypeScript import { logger$ } from '@marblejs/middleware-logger'; const middlewares = [ logger$(), ... ]; const effects = [ ... ]; export const app = httpListener({ middlewares, effects }); ``` -------------------------------- ### Using @marblejs/middleware-multipart for In-Memory File Handling (TypeScript) Source: https://github.com/marblejs/marble/blob/master/packages/middleware-multipart/README.md This snippet demonstrates the basic usage of the `multipart$()` middleware to parse incoming multipart/form-data requests. By default, it stores uploaded files in memory. It shows how to apply the middleware to a specific route and access parsed files and body fields from the request object. ```typescript import { multipart$ } from '@marblejs/middleware-multipart'; const effect$ = r.pipe( r.matchPath('/'), r.matchType('POST'), r.useEffect(req$ => req$.pipe( multipart$(), map(req => ({ body: { files: req.files['image_1'], // file information body: req.body // all incoming body fields }})) ))); ``` -------------------------------- ### CORSOptions Interface Definition Source: https://github.com/marblejs/marble/blob/master/packages/middleware-cors/README.md This snippet defines the TypeScript interface `CORSOptions`, which specifies the available configuration properties for the `cors$` middleware. It lists properties like `origin`, `methods`, `optionsSuccessStatus`, `allowHeaders`, `exposeHeaders`, `withCredentials`, and `maxAge`, along with their expected types. ```typescript interface CORSOptions { origin?: string | string[] | RegExp; methods?: HttpMethod[]; optionsSuccessStatus?: HttpStatus; allowHeaders?: string | string[]; exposeHeaders?: string[]; withCredentials?: boolean; maxAge?: number; } ``` -------------------------------- ### Using @marblejs/middleware-io for Request Body Validation (TypeScript) Source: https://github.com/marblejs/marble/blob/master/packages/middleware-io/README.md Demonstrates how to use `requestValidator$` from `@marblejs/middleware-io` to validate the request body against a defined `io-ts` schema within a Marble.js HTTP effect. It defines a schema for a 'User' object and applies it to a POST request. ```TypeScript import { r } from '@marblejs/http'; import { requestValidator$, t } from '@marblejs/middleware-io'; const userSchema = t.type({ id: t.string, firstName: t.string, lastName: t.string, roles: t.array(t.union([ t.literal('ADMIN'), t.literal('GUEST'), ])), }); type User = t.TypeOf; const effect$ = r.pipe( r.matchPath('/'), r.matchType('POST'), r.useEffect(req$ => req$.pipe( requestValidator$({ body: userSchema }), // .. ))); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.