Fiber
Build a statically typed SDK for your backend in minutes.
Source code is hosted on GitHub
Create a statically typed client for remote, RPC style communication. Consume your backend API through a statically typed facade, without any code generation, without writing any custom API calls or duplicating your backend types on the client side. Fiber works in any TypeScript setup and is fully implementation agnostic.
Full static typing from tail to toe
You control the implementation
Works for client to server and server to server communication
Build an SDK for your backend in minutes
No code generation, plain TypeScript
yarn add @corets/fibernpm install --save @corets/fiberQuick start
First you create a fiber instance and register all the methods that you want to expose to consumers:
import { createFiber } from "@corets/fiber"
const makeResponse = (status: number, result: any) => {
return { status, result }
}
const pingPong = (input: string) => {
return makeResponse(200, input === "ping" ? "pong" : "ping")
}
export const fiber = createFiber({ pingPong })
export type MyFiber = typeof fiberNext you need to setup your server, we'll be using express in this example:
Next you create a consumer for your fiber, on the client side, we'll use axios in this example:
Now you have a statically typed, RPC style client, that you can consume immediately:
createFiber()
Create a new fiber instance on the producer side, returns an instance of SimpleFiber:
createFiberClient()
Create a statically typed fiber client, returns an instance of SimpleFiberClient:
SimpleFiber.call()
Call a registered fiber method on the producer side:
SimpleFiberClient.call()
Last updated
Was this helpful?