Marble.js

repository·master·Indexed 24 days ago

https://github.com/marblejs/marble

A functional reactive Node.js framework for building server-side applications, built on TypeScript and RxJS. It provides a modular ecosystem including @marblejs/core, @marblejs/http, @marblejs/websockets, and @marblejs/messaging, along with specialized middlewares for logging, body parsing, I/O validation, CORS, and multipart file handling.

Tokens
21.2K
Snippets
58
Records
145
Agent score
80%

What's inside marblejs

  1. What is Marble.js?

    master
    Marble.js is a functional reactive Node.js framework designed for building server-side applications. It is built using TypeScript and leverages RxJS to provide a reactive programming model for server-side logic.
  2. Explore Marble.js integration examples

    master
    The @marblejs/integration package provides a collection of reference implementations demonstrating how to combine various Marble.js modules. These examples cover common architectural patterns such as REST APIs, CQRS with EventBuses, messaging with RabbitMQ/Redis, and WebSocket servers.
  3. Marble.js Ecosystem and Modules

    master

    Marble.js is composed of several specialized modules that can be used to build different parts of a server-side application:

    • @marblejs/core: The framework's core module.
    • @marblejs/http: Provides HTTP capabilities.
    • @marblejs/websockets: Provides WebSocket support.
    • @marblejs/messaging: Provides messaging capabilities.
    • @marblejs/testing: Provides testing utilities.
    • @marblejs/middleware-logger: Logger middleware.
    • @marblejs/middleware-body: Body parser middleware.
    • @marblejs/middleware-io: I/O validation middleware.
    • @marblejs/middleware-cors: CORS middleware.
    • @marblejs/middleware-multipart: Multipart middleware.
  4. Use the CORS middleware in Marble.js

    master

    To enable Cross-Origin Resource Sharing (CORS) in your Marble.js application, import cors$ from @marblejs/middleware-cors and include it in your middlewares array when initializing your httpListener. This allows you to control which origins, methods, and headers are permitted for incoming requests.

    import { cors$ } from '@marblejs/middleware-cors';
    
    const middlewares = [
      logger$,
      cors$(
        {
          origin: '*', // Allow all origins
          methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
          optionsSuccessStatus: 204,
          allowHeaders: '*', // Allow all headers
          maxAge: 3600,
        }
      )
    ];
    
    const effects = [
      endpoint1$,
      endpoint2$,
      ...
    ];
    
    const app = httpListener({ middlewares, effects });
  5. Manage dependencies using Context

    master

    Marble.js uses a Context object to implement dependency injection. A Context is essentially a map where keys are ContextTokens and values are ContextDependencys. Dependencies can be provided in two ways:

    1. Eager Dependencies (ContextEagerReader): Evaluated immediately when the context is resolved.
    2. Lazy Dependencies (ContextLazyReader): Evaluated only when the dependency is looked up for the first time.

    To build a context, you can use createContext() to start with an empty context, and then use register, registerAll, bindLazilyTo, or bindEagerlyTo to populate it.