tyfon init
tyfon build
tyfon serve
tyfon watch
tyfon install
tyfon uninstall
tyfon help
tyfon version
1link// server:
2link
3linkexport async function getMessage(name: string) {
4link return `Hellow ${name}!`;
5link}
1link// client:
2link
3linkimport { getMessage } from '@api/my-server';
4link
5linkgetMessage('World').then(console.log):
To get a feeling of how TyFON works, lets create a simple server and client. You need Node.js installed before you can proceed.
1link$npm i -g tyfon
👉 Create a folder for your server code.
1link$mkdir my-tyfon-server
2link$cd my-tyfon-server
👉 Create package.json
:
1link{
2link "name": "my-tyfon-server"
3link}
👉 Create index.ts
:
1linkexport interface User {
2link name: string;
3link}
4link
5linkexport const getMessage = async (user: User) => `Hellow ${user.name}!`;
🚀 Serve it:
1link$tyfon serve
Check it out on http://localhost:8000/message?0={"name":"World"}
👉 In a new terminal, create a folder for your client code (keep the server running):
1link$mkdir my-tyfon-client
2link$cd my-tyfon-client
3link$npm i -g ts-node # --> To run TypeScript. You can also skip this and run JavaScript.
4link$npm init
👉 Install your server's SDK:
1link$tyfon i localhost:8000
👉 Create index.ts
:
1linkimport { getMessage, User } from '@api/my-tyfon-server';
2link
3linkconst john: User = {
4link name: 'John'
5link};
6link
7linkgetMessage(john).then(console.log);
🚀 Run it:
1link$ts-node .
Hellow John!
TyFON leans heavily on convention over configuration principle. There are conventions it
uses under the hood for consistent server-client communication, and there are conventions you would
need to follow. For example, function names will determine the endpoint URL and method (under the hood convention),
and your remote functions must always be exported from index.ts
.
tyfon init
Initializes TyFON
tyfon build
Builds network layer code and SDK metadata. Also can be used to build production Docker images.
tyfon serve
Serves the functions exported from index.ts
over network.
tyfon watch
Serves and watches the functions exported from index.ts
over network.
tyfon install
Installs SDK of a TyFON server, or installs/updates all required SDKs specified in package.json
.
tyfon uninstall
Uninstalls a particular SDK.
On server-side, TyFON simply injects necessary networking code and runs a Node server. It also compiles the TypeScript code and bundles the type definitions into SDK metadata.
On client-side, the CLI requests that SDK metadata from the server. It then generates a local package from that metadata, using same type definitions as the exported server code, and auto-generating necessary networking code. Client SDK's network layer is isomorphic, so you can use it on other Node instances as well as in browsers.