Giter Club home page Giter Club logo

sdkgen's Introduction

sdkgen

test status badge telegram badge

Getting Started

Installing sdkgen

First of all you need Node.js 12 or newer on your machine. We recommend using the latest LTS version, 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

sdkgen's People

Contributors

lbguilherme avatar dgadelha avatar kevinoliveira avatar renovate[bot] avatar danielpsantiago avatar dependabot[bot] avatar dependabot-preview[bot] avatar daniloapr avatar joshuapassos avatar danilocubos avatar thiagoarmede avatar renatovassao avatar mrmenezes avatar michelribeiro1 avatar ahardmann avatar biracubos37 avatar yansb avatar elcioabrahao avatar leleofg avatar giurigaud avatar guibernal avatar igorp984 avatar josecleiton avatar manoellribeiro avatar hofstede-matheus avatar davidcpires 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.