# vite-plugin-open-client

> Provides a HTTP client based on a OpenAPI specification

Latest version **0.0.6** (published 2022-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-open-client
pnpm add vite-plugin-open-client
yarn add vite-plugin-open-client
bun add vite-plugin-open-client
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2022-10-14 |
| First published | 2022-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 25.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Henrique Cunha |
| Maintainers | henrykunh |
| Keywords | vite, vite-plugin |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-open-client
- npm.io page: https://npm.io/package/vite-plugin-open-client

## Dependencies (4)

- [axios](https://npm.io/package/axios.md) ^1.0.0
- [unplugin](https://npm.io/package/unplugin.md) ^0.9.6
- [kleur-template](https://npm.io/package/kleur-template.md) ^0.0.3
- [openapi-typescript](https://npm.io/package/openapi-typescript.md) ^5.4.1

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2022-10-14
- 0.0.5 — 2022-10-13
- 0.0.4 — 2022-10-13
- 0.0.3 — 2022-10-13
- 0.0.2 — 2022-10-13
- 0.0.1 — 2022-10-13
- 0.0.0 — 2022-10-13

## README

# open-client

[![npm](https://img.shields.io/npm/v/vite-plugin-open-client.svg)](https://www.npmjs.com/package/vite-plugin-open-client)

> Provides a fully typed HTTP client based on a OpenAPI specification

&nbsp;

### 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 } 
})


```

---
_Source: https://npm.io/package/vite-plugin-open-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
