tyfon v0.2.10
TyFON is a zero-config RPC for TypeScript. It automatically creates all required networking code on the server-side and generates client-side SDK using same type definitions for client-server consistency.
// server:
export async function getMessage(name: string) {
return `Hellow ${name}!`;
}// client:
import { getMessage } from '@api/my-server';
getMessage('World').then(console.log):š Read the docs.
Installation
TyFON is a singular CLI tool that runs on Node, so you need Node.js installed beforehand.
npm i -g tyfonUsage
Read the docs for detailed usage information and a getting-started tutorial.
Server Side
Export your functions in index.ts:
export async const getMessage = name => `Hellow ${name}!`;Now serve them:
tyfon serveš Check it out on localhost:8000/message?0="World".
Client Side
Add the SDK on client side and use it:
tyfon i localhost:8000import { getMessage } from '@api/my-server';
getMessage('World').then(console.log);š The name my-server comes from package.json of your server code.
Syncing Updates
Use tyfon watch while working on server and client simultaneously:
tyfon watch -c <client-path> # --> run this on server side codeOr sync updates manually (in other situations):
- On server-side code, rebuild client SDK metadata and serve it again:
tyfon build # --> run this on server side codetyfon serve # --> run this on server side code- On client-side code, update TyFONs you are using:
tyfon i # --> run this on client side codeServer Environment Variables
You can pass environment variables to typhon serve command using -e option:
typhon serve -e ENV=dev -e LOGS=verboseClient Environments
It is common practice for client-code to use different API URLs for different environments (i.e. development, production, staging, etc).
You can use the --env flag on typhon i command to mark the environment a TyFON should be used in:
tyfon i https://my-server.cloud --env production
tyfon i https://staging.my-server.cloud --env staging
tyfon i localhost:8000 --env devNow for building client-code in production, use the following command:
tyfon i --env production # --> this will install all generic TyFONs and all production TyFONsDeploying
Run your TyFON in production mode:
tyfon serve --mode prodDocker
Build a docker image and deploy it:
tyfon build --image my-server
docker tag my-server https://my-registry.cloud/my-server
docker push my-serverš docker MUST be installed for using this option.
Conventions
TyFON leans heavily towards the convention over configuration principle. It is pretty opinionated in how it wraps normal functions within
API end-points and how code should be structured, for example it picks endpoint methods based on the name of the function, or it expects
all API functions to be exported from index.ts from the root of the project.
š Read the docs.
CLI Commands
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago