0.0.3 • Published 4 months ago
@somnolence/cli v0.0.3
💤 Somnolence CLI — Generate type-safe clients from any Somnolence Server and rest easy
Somnolence CLI generates type-safe clients from any server running Somnolence. You don't ened access to the server's source code to get its TypeScript types. Just point the CLI at any Somnolence Server and get one generated automatically!
Install
# NPM
$ npm install -g @somnolence/cli
# PNPM
$ pnpm add -g @somnolence/cli
# Yarn
$ yarn global add @somnolence/cli
# Bun
$ bun add -g @somnolence/cli
Usage
Generate the client:
# path/to/your/client
$ somnolence-ts --endpoint https://my-cool-app.com/path/to/my-somnolence-server
# 💤 Generated Somnolence Client at node_modules/@somnolence/client
Use the type-safe client:
import somnolence from '@somnolence/client'
somnolence
.hello({ query: { name: 'world' } })
.then(response => console.log(response.body)) // 'Hello, world!'
The client infers the inputs and outputs of each route:
The client automatically knows what inputs are required
The client automatically knows the response is a string
CLI Options
$ somnolence-ts --help
Usage
$ somnolence-ts
Options
--endpoint Endpoint for your Somnolence Server (default: http://localhost:3000)
--outdir Output directory for the generated, type-safe client (default: node_modules/@somnolence/client)
Examples
$ somnolence-ts --endpoint=https://backend.my-app.com
💤 Generated Somnolence Client at node_modules/@somnolence/client