Star

Created With

logo

logo

Seamlessly use server-side TypeScript functions (and types) on the client.
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):


linkGetting Started

To get a feeling of how TyFON works, lets create a simple server and client. You need Node.js installed before you can proceed.


linkInstall TyFON

1link$npm i -g tyfon


linkSetup a Server

👉 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"}



linkSetup a Client

👉 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!

linkConventions

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.

Learn More About TyFON Conventions

linkCLI Commands

linkServer-Side

linkClient-Side

linkGeneric


linkUnder the Hood

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.



Getting StartedInstall TyFONSetup a ServerSetup a ClientConventionsCLI CommandsServer-SideClient-SideGenericUnder the Hood

Home Conventions Error Handling

CLI Referencechevron_right
Advanced Usagechevron_right