Executors
An executor is the transport layer — it handles the actual HTTP call. routar ships with three built-in executors:
| Package | Executor | Best for |
|---|---|---|
@routar/core | createFetchExecutor | SSR, Node.js 18+, zero dependencies |
@routar/axios | createAxiosExecutor | CSR, existing Axios instances, interceptors |
@routar/ky | createKyExecutor | CSR/SSR, ky hooks, modern fetch-based clients |
All implement the same Executor interface and are interchangeable — you can use createFetchExecutor on the server and @routar/axios or @routar/ky in the browser with the exact same router definition.
Choosing an executor
Use createFetchExecutor (built into @routar/core) when:
- You need per-request dynamic headers (SSR / Server Components)
- You want zero extra dependencies beyond routar itself
- You’re targeting Node.js 18+ or any modern browser
Use @routar/axios when:
- You already have an Axios instance with interceptors configured
- You’re building a CSR-only app and Axios is already a dependency
Use @routar/ky when:
- You prefer ky’s hook system for request/response lifecycle
- You want a modern fetch-based client with a clean API
Custom executors
Any HTTP client works with routar. Wrap it with createExecutor from @routar/core. See the Custom Executor guide.
Runtime dispatch
When you need to pick one of several executors per request (e.g. SSR vs CSR, or environment-specific base URLs), wrap them with dispatchExecutor.
Last updated on