Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vtex/node-vtex-api
VTEX IO API Client for Node
https://github.com/vtex/node-vtex-api
node npm srv-io-web-framework vtex-io xp-developer
Last synced: 3 days ago
JSON representation
VTEX IO API Client for Node
- Host: GitHub
- URL: https://github.com/vtex/node-vtex-api
- Owner: vtex
- Created: 2016-05-25T18:04:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-11T18:55:54.000Z (7 months ago)
- Last Synced: 2024-09-20T09:22:33.309Z (4 months ago)
- Topics: node, npm, srv-io-web-framework, vtex-io, xp-developer
- Language: TypeScript
- Homepage:
- Size: 3.58 MB
- Stars: 75
- Watchers: 143
- Forks: 16
- Open Issues: 51
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
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.
[![Build Status](https://travis-ci.org/vtex/node-vtex-api.svg?branch=master)](https://travis-ci.org/vtex/node-vtex-api)
## 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:
```javascript
// 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:
```javascript
export const example = async (ctx: Context, next: () => Promise) => {
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`
- Watch for changes: `yarn watch`### Development with IO clients
- Install the dependencies: `yarn`
- [Link](https://classic.yarnpkg.com/en/docs/cli/link/) this package: `yarn link`
- Watch for changes: `yarn watch`
- Move to the app that depends on the changes made on this package: `cd ..//node`
- Link this package to your app's node_modules: `yarn link @vtex/api`Now, when you get a workspace up and running for your app with `vtex link`, you'll have this package linked as well.
> When done developing, don't forget to unlink it from `/node`: `yarn unlink @vtex/api`