Giter Club home page Giter Club logo

apifly's Introduction

apifly

JSR

👋 👋 ATTENTION!

This package is under development and will be frequently updated. The author would appreciate any help, advice, and pull requests! Thank you for your understanding 😊

apifly is a small typed library designed for state sharing in client-server applications and remote procedure calls for different runtime environments.

Quick Start:

1. Обределить тип состояния и процедур в MyApiflyDefinition.ts:

import { ApiflyDefinition } from "@vseplet/apifly/types";

export type MyApiflyDefinition = ApiflyDefinition<
  {
    a: {
      b: string;
      c: {
        d: boolean;
      };
    };
  },
  {
    hi: {
      args: [];
      returns: string;
    };
  }
>;

2. Создать клиент (используется @vseplet/fetchify):

import apifly from "@vseplet/apifly";
import type { MyApiflyDefinition } from "./MyApiflyDefinition.type.ts";

export const client = new apifly.client<MyApiflyDefinition>({
  baseURL: "http://localhost:8000/api/apifly",
  limiter: {
    unlimited: true,
  },
});

3. Создать сервер (на примере hono):

import apifly from "@vseplet/apifly";
import type { MyApiflyDefinition } from "./MyApiflyDefinition.ts";
import { Hono } from "@hono/hono";

const apiflyServer = new apifly.server<MyApiflyDefinition>()
  .load(async () => {
    return {
      a: {
        b: "1",
        c: {
          d: true,
        },
      },
    };
  })
  .procedure("hi", async (args) => {
    return "Hello, World";
  });

const server = new Hono();
const api = new Hono();
api.post( // это можно встраивать и миксовать с основным api
  "/apifly",
  async (c) => c.json(await apiflyServer.handleRequest(await c.req.json())),
);
server.route("/api", api);
Deno.serve(server.fetch);

apifly's People

Contributors

vseplet avatar github-actions[bot] avatar artpani4 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.