Giter VIP home page Giter VIP logo

node-vtex-api's Introduction

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

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<void>) => {
  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 this package: yarn link
  • Watch for changes: yarn watch
  • Move to the app that depends on the changes made on this package: cd ../<your-app>/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 <your-app>/node: yarn unlink @vtex/api

node-vtex-api's People

Contributors

guifromrio avatar tlgimenes avatar tiagonapoli avatar vwraposo avatar natalia-godot avatar becageuse avatar jeymisson avatar vcalasans avatar pedroig avatar dhasuda avatar amoreira avatar arturpimentel avatar tamorim avatar rdumont avatar marcelovicentegc avatar verasthiago avatar diegoximenes avatar iagoaraujo avatar mcandeia avatar rogerlucena avatar gris avatar gustavorosolem avatar viniagostini avatar thiagomurakami avatar juaresba avatar jgfidelis avatar victorges avatar brunoabreu avatar victorcolombo avatar klzns avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.