Silgi
Plugins

Server Batch

Handle multiple RPC calls in a single HTTP request — pairs with the client-side BatchLink.

The batch handler processes multiple procedure calls in one HTTP round-trip. It pairs with the client-side BatchLink to reduce network overhead when your UI makes many calls at once.

Setup

import {  } from 'silgi/plugins'

const  = (appRouter, {
  : () => ({ : getDB() }),
  : 20,
})

Mount alongside your normal handler — for example at /batch:

// Using handler()
const  = s.handler(appRouter)

export default {
  async (: Request) {
    const  = new (.)
    if (. === '/batch') return batchHandler()
    return ()
  },
}

Protocol

The client sends a POST with a JSON array of calls:

[
  { "path": "users/list", "input": { "limit": 10 } },
  { "path": "users/get", "input": { "id": 1 } }
]

The server returns a JSON array of results (same order):

[{ "data": [{ "id": 1, "name": "Alice" }] }, { "data": { "id": 1, "name": "Alice", "email": "[email protected]" } }]

If a call fails, its entry has an error instead of data:

[
  { "data": [{ "id": 1, "name": "Alice" }] },
  { "error": { "code": "NOT_FOUND", "status": 404, "message": "User not found" } }
]

Options

OptionTypeDefaultDescription
context(req) => TCtx(required)Context factory — called once per batch
maxBatchSizenumber50Maximum calls per batch

All calls in a batch share the same context (computed once from the HTTP request). Each call runs the full compiled pipeline including guards, wraps, and validation.

The batch handler executes all calls concurrently with Promise.all. If you need sequential execution, use separate requests or implement a custom batch handler.

Client setup

Use BatchLink from the client plugins:

import {  } from 'silgi/client/plugins'

const  = new ({
  : 'http://localhost:3000',
  : '/batch',
  : 10,
})

What's next?

On this page