Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sdkgen/sdkgen
sdkgen is a tool to help design, implement and maintain good APIs with minimal effort
https://github.com/sdkgen/sdkgen
api csharp dart hacktoberfest kotlin restful rpc sdkgen typescript
Last synced: 9 days ago
JSON representation
sdkgen is a tool to help design, implement and maintain good APIs with minimal effort
- Host: GitHub
- URL: https://github.com/sdkgen/sdkgen
- Owner: sdkgen
- License: mit
- Created: 2020-02-06T17:14:06.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-12-19T13:28:09.000Z (11 months ago)
- Last Synced: 2023-12-19T16:11:33.521Z (11 months ago)
- Topics: api, csharp, dart, hacktoberfest, kotlin, restful, rpc, sdkgen, typescript
- Language: TypeScript
- Homepage: https://sdkgen.github.io/
- Size: 3.05 MB
- Stars: 68
- Watchers: 8
- Forks: 37
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sdkgen
[![test status badge](https://github.com/sdkgen/sdkgen/workflows/test/badge.svg?branch=main)](https://github.com/sdkgen/sdkgen/actions)
[![telegram badge](https://img.shields.io/badge/telegram-sdkgen-179CDE)](https://t.me/sdkgen)# 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 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:
```typescript
// 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
```