An open API service indexing awesome lists of open source software.

https://github.com/spacecloud-io/space-sdk-ts

Typescript API for Space Cloud
https://github.com/spacecloud-io/space-sdk-ts

Last synced: 12 months ago
JSON representation

Typescript API for Space Cloud

Awesome Lists containing this project

README

          

# Space SDK (Typescript)
Typescript API for Space Cloud

## Worker API

### Sample usage
```ts
import { Server } from "@spacecloud-io/worker";
import { z } from "zod";

// We first create the server object
const server = Server.create({
name: "myServer",
baseUrl: "/v2", // Optional. Defaults to `/v1`.
port: 8080 // Optional. Defaults to `3000`.
});

// Create a router object. All operations are registered on this router.
const router = server.router();

// Register a query object.
router.query("operate") // `opId` is the name of the operation
.method("GET") // Defaults to `GET` for queries and `POST` for mutations
.url("/v1/operate") // Defaults to `${baseUrl}/${opId}`
.input(z.object({ name: z.string() }))
.output(z.object({ greeting: z.string() }))
.fn(async (_ctx, req) => {
return { greeting: `Hi ${req.name}` };
});

// Start the express http server.
server.start();
```

The worker generates the some additional routes as shown below:

```
# Routes created to expose the OpenAPI specification generated
[GET] `${baseUrl}/openapi.json`
[GET] `${baseUrl}/openapi.yaml`
```

### Saving OpenAPI specification to disk

Simply add the flag `--save-openapi` flag to save the autogenerated Open API specification in yaml format. Use the `-f, --file ` flag to control the file path. The specification will be persisted at `${file}/openapi.yaml`.
```
node index.js --save-openapi -f ./config
```