Package Exports
- @vtex/api
- @vtex/api/lib/HttpClient/AppClient
- @vtex/api/lib/HttpClient/AppClient.js
- @vtex/api/lib/HttpClient/AppGraphQLClient
- @vtex/api/lib/HttpClient/AppGraphQLClient.js
- @vtex/api/lib/HttpClient/IOClient
- @vtex/api/lib/HttpClient/IOClient.js
- @vtex/api/lib/HttpClient/middlewares/cache
- @vtex/api/lib/HttpClient/middlewares/cache.js
- @vtex/api/lib/clients/Apps
- @vtex/api/lib/clients/Apps.js
- @vtex/api/lib/clients/Housekeeper
- @vtex/api/lib/clients/Housekeeper.js
- @vtex/api/lib/clients/Registry
- @vtex/api/lib/clients/Registry.js
- @vtex/api/lib/clients/Router
- @vtex/api/lib/clients/Router.js
- @vtex/api/lib/clients/Workspaces
- @vtex/api/lib/clients/Workspaces.js
- @vtex/api/lib/index.js
- @vtex/api/lib/service/logger
- @vtex/api/lib/service/logger/index.js
- @vtex/api/lib/utils/app
- @vtex/api/lib/utils/app.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@vtex/api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
VTEX IO API Client for Node
This library enables developers to quickly integrate with the VTEX IO APIs and create full fledged node services using VTEX IO.
Getting started
For a complete example on using @vtex/api, check out this app: https://github.com/vtex-apps/service-example
The most basic usage is to export a new Service() with your route handlers:
// Import global types
import './globals'
import { Service } from '@vtex/api'
import { clients } from './clients'
import example from './handlers/example'
// Export a service that defines route handlers and client options.
export default new Service({
clients,
routes: {
example,
},
})This allows you to define middlewares that receive a Context param which contains all IO Clients in the clients property:
export const example = async (ctx: Context, next: () => Promise<any>) => {
const {state: {code}, clients: {apps}} = ctx
console.log('Received code:', code)
const apps = await apps.listApps()
ctx.status = 200
ctx.body = apps
ctx.set('Cache-Control', 'private')
await next()
}ctx.clients.apps is an instance of Apps.
Development
Install the dependencies (yarn) and run yarn watch.