https://github.com/henrycunh/open-client
🖇 Create a HTTP Client/SDK from your API, fully-typed and with amazing DX
https://github.com/henrycunh/open-client
client dx http open-api typescript vite
Last synced: 2 months ago
JSON representation
🖇 Create a HTTP Client/SDK from your API, fully-typed and with amazing DX
- Host: GitHub
- URL: https://github.com/henrycunh/open-client
- Owner: henrycunh
- License: mit
- Created: 2022-09-09T21:30:13.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-13T05:09:31.000Z (over 2 years ago)
- Last Synced: 2025-04-04T16:13:57.824Z (3 months ago)
- Topics: client, dx, http, open-api, typescript, vite
- Language: TypeScript
- Homepage:
- Size: 74.2 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# open-client
[](https://www.npmjs.com/package/vite-plugin-open-client)
> Provides a fully typed HTTP client based on a OpenAPI specification
Â
### install
```
pnpm i -D vite-plugin-open-client
```### use it
##### `vite.config.ts`
```ts
import OpenClient from 'vite-plugin-open-client'export default {
plugins: [
OpenClient({
definition: 'https://petstore.swagger.io/v2/swagger.json',
apiName: 'petstore'
})
]
}
```##### `main.ts`
```ts
import { defineClient } from 'api:petstore'
import type { APISchema } from 'api:petstore'const client = defineClient({
baseUrl: 'https://api.petstore.com/',
headers: {
Apikey: 'my-api-key'
}
})// You can either alias the operations
const getPetById = client('/pet/{petId}', 'get')
const createPet = client('/pet', 'post')
console.log(
await getPetById({
path: { petId: 1 }
})
)// You can borrow type definitions from the specification
const pet: APISchema<'Pet'> = {
name: 'dog',
photoUrls: ['https://example.com/dog.jpg'],
}
await createPet({ body: { body: pet }})// Or call them directly through path
await client('/pet/{petId}', 'delete')({
path: { petId: 1 }
})```