Get Started (with express)
Getting started is easy! Just follow these few steps:
-
Install packages
npm i express apizy apizy-express
-
Create and expose an API in your backend application.
import { createApi } from 'apizy'; import apizyExpress from 'apizy-express'; import express from 'express'; const api = createApi(); // API methods and types definitions here ... api.createMethod( 'helloWorld', // <-- Name of the method string(), // <-- Input data string(), // <-- Output data async (input) => { // <-- Handler return `Hello, ${input}!`; }, ); const app = express(); app.use('/api', apizyExpress(api, { devTools: { enabled: true, // Enables dev tools like interactive documentation // Documentation available at /api/dev // SDK available at /api/dev/sdk.ts }, })); app.listen(8080);
-
Add a script to your frontend application
package.json
:"scripts": { "update-sdk": "curl http://localhost:8080/api/dev/sdk.ts -o src/sdk.auto.ts" }
Run it to download up-to-date SDK definitions. Usually you’d like to do it from your local or test server.
-
Initialize the SDK in your frontend application:
import { createSDK } from './sdk.auto.ts'; const sdk = createSDK('http://localhost:8080/api');
-
Call your methods on sdk:
sdk.helloWorld('John'); // -> Promise<'Hello, John!'>
Your SDK is ready to go! Start declaring and calling your first methods—it’s as simple as that!