VTEX IO powers big ecommerce operations, and for most of that it's necessary to run code on a server. Services are how we run Node.js or .NET code on VTEX IO infrastructure, backed by API abstractions to improve developer experience.
Services can export HTTP Routes, GraphQL resolvers or event handlers.
Using the builders node
or dotnet
, you can export services from a VTEX IO app, just like themes or store blocks. It's easy to quickly setup, for example, a REST API with that.
The service.json
file
The service.json
is a file that must exist on the folder of the service (node/
or dotnet/
), and it's with this file that you may declare routes or events that the service must respond to. It also configures parameters like timeout and memory about the deployment of that service.
This is the node/service.json
from vtex.service-example app:
_13{_13 "memory": 256,_13 "ttl": 10,_13 "timeout": 2,_13 "minReplicas": 2,_13 "maxReplicas": 4,_13 "routes": {_13 "status": {_13 "path": "/_v/status/:code",_13 "public": true_13 }_13 }_13}
After defining these configs, it's possible to export handler functions on node/index.ts file. Most of the fields on the service.json are optional, and default values will be used by the platform. | Name | Type | Description | | --- | --- | --- | | routes | Object | A map from the name of a route handler you want to another object declaring path, public or other information about ReBAC | | events | Object | A map from the name of a event handler on the code to another object describing sender or keys | | memory | Number | In MB. The size of memory to be allocated to that service. | | ttl | Number | In minutes. Time that the platform will keep the service running without receiving any requests. Default: 10. Max: 120 | | timeout | Number | In seconds. VTEX IO infra will abort the connection if the request time is longer than that | | minReplicas | Number | When the service is running, how many minimum replicas will be available. | | maxReplicas | Number | The largest amount of replicas that will be available. | | workers | Number | Numbers of workers to spawn for that service on production. (Max: 4) |
It's also possible to export GraphQL services, using the graphql builder. You can check vtex.graphql-example to see how it's done.