Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apiverse

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apiverse

Unified, pluggable API client management

  • 0.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

apiverse

npm version bundle

apiverse provides a unified way to manage all your API interactions by setting up a client with default fetch options, such as the API base URL and headers. Adapters extend the client with a variety of features to match your favorite API management flavor.

You can use one of the pre-built adapters to get started quickly, or create your own custom adapter to meet your specific requirements.

Setup

[!TIP] 📖 Read the documentation

# pnpm
pnpm add -D apiverse

# npm
npm i -D apiverse

Usage

[!TIP] 📖 Read the documentation

ofetch Adapter

import { createClient, ofetch } from 'apiverse'

const baseURL = '<your-api-base-url>'
const adapter = ofetch()
const api = createClient({ baseURL }).with(adapter)

// GET request to <baseURL>/users/1
await api('users/1', { method: 'GET' })

What it does:

The ofetch adapter wraps ofetch to handle API calls.

apiRouteBuilder Adapter

import { apiRouteBuilder, createClient } from 'apiverse'

const baseURL = '<your-api-base-url>'
const adapter = apiRouteBuilder()
const api = createClient({ baseURL }).with(adapter)

// GET request to <baseURL>/users/1
await api.users.get(1)
// POST request to <baseURL>/users with payload
await api.users.post({ name: 'foo' })

What it does:

The apiRouteBuilder adapter provides a jQuery-like and Axios-esque API for building and making API calls. It allows you to construct your API calls in a declarative way.

OpenAPI Adapter

import { OpenAPI, createClient } from 'apiverse'

const baseURL = 'https://petstore3.swagger.io/api/v3'
// Pass pre-generated schema type ID to adapter
const adapter = OpenAPI<'petStore'>()
const api = createClient({ baseURL }).with(adapter)

// Typed parameters and response
const response = await api('/user/{username}', {
  method: 'GET',
  path: { username: 'user1' },
})

What it does:

If your API has an OpenAPI schema, apiverse can use it to generate types for you, which the OpenAPI adapter then consumes to provide type-safe API calls.

For example, the response returned by the API call on the left is typed as follows:

const response: {
  id?: number
  username?: string
  // …
}

Please follow the OpenAPI adapter documentation to learn more about how to generate TypeScript definitions from your OpenAPI schema files.

Outlook & Roadmap

As of right now, this library handles API management in the client. In the future, apiverse is intended to extend to the server side as well, providing a unified way to manage API calls in both client and server.

Development

  • Clone this repository
  • Install latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛

Published under MIT License.

Keywords

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc