Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sdkgen is a tool to help design, implement and maintain good APIs with minimal effort

License

NotificationsYou must be signed in to change notification settings

sdkgen/sdkgen

Repository files navigation

test status badgetelegram badge

Getting Started

Installing sdkgen

First of all you need Node.js 16 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 anapi.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 withsdkgen api.sdkgen -o api.ts -t typescript_nodeserver.

Creating base project

Let's start a new project with TypeScript:

npm init -ynpm i --save-dev typescriptnpm i @sdkgen/node-runtimenpx tsc --init -t esnext

Then create amain.ts file:

// Import sdkgen's runtime and the generated fileimport{SdkgenHttpServer}from"@sdkgen/node-runtime";import{api}from"./api";// Every endpoint described must receive some implementationapi.fn.getPost=async(ctx,{ id})=>{return{    id,title:"Getting Started",author:{name:"John Doe"},body:"Lorem ipsum",createdAt:newDate(),};};// Start a HTTP server for the APIconstserver=newSdkgenHttpServer(api);server.listen(8000);

Run the project

Build and run it:

npx tscnode main.js

About

sdkgen is a tool to help design, implement and maintain good APIs with minimal effort

Topics

Resources

License

Stars

Watchers

Forks

Contributors36


[8]ページ先頭

©2009-2025 Movatter.jp