Skip to content

danilocubos/sdkgen

 
 

Repository files navigation

sdkgen

test status badge telegram badge

Getting Started

Installing sdkgen

First of all you need Node.js ready on your machine. Versions 10, 12, 14 or 15 are supported (all stable maintained release channels). Check for it here: https://nodejs.org/en/download/

Install the global CLI:

npm i -g @sdkgen/cli

Creating an API description

Create an api.sdkgen to describe your API. For example:

type Post {
    id: uuid
    title: string
    body: string
    createdAt: datetime
    author: {
        name: string
    }
}

fn getPost(id: uuid): Post?

You can then generate the TypeScript source for this description with sdkgen api.sdkgen -o api.ts -t typescript_nodeserver.

Creating base project

Let's start a new project with TypeScript:

npm init -y
npm i --save-dev typescript
npm i @sdkgen/node-runtime
npx tsc --init -t esnext

Then create a main.ts file:

// Import sdkgen's runtime and the generated file
import { SdkgenHttpServer } from "@sdkgen/node-runtime";
import { api } from "./api";

// Every endpoint described must receive some implementation
api.fn.getPost = async (ctx, {id}) => {
    return {
        id,
        title: "Getting Started",
        author: {
            name: "John Doe"
        },
        body: "Lorem ipsum",
        createdAt: new Date(),
    };
};

// Start a HTTP server for the API
const server = new SdkgenHttpServer(api, {});
server.listen(8000);

Run the project

Build and run it:

npx tsc
node main.js

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 80.9%
  • Dart 5.4%
  • C# 4.5%
  • Kotlin 3.5%
  • SCSS 2.9%
  • JavaScript 2.0%
  • HTML 0.8%