0.0.6 • Published 2 years ago

vite-plugin-open-client v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

open-client

npm

Provides a fully typed HTTP client based on a OpenAPI specification

 

install

pnpm i -D vite-plugin-open-client

use it

vite.config.ts
import OpenClient from 'vite-plugin-open-client'

export default {
    plugins: [
        OpenClient({
            definition: 'https://petstore.swagger.io/v2/swagger.json',
            apiName: 'petstore'
        })
    ]
}
main.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 } 
})
0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago