Overview of VTEX IO Services
VTEX IO powers large ecommerce operations, most of which require running code on a server. Services run Node.js or .NET code on VTEX IO infrastructure and provide API abstractions that improve the 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. For example, you can quickly set up a REST API this way.
The service.json file
The service.json is a file that must exist in the folder of the service (node/ or dotnet/), and you use this file to declare routes or events that the service must respond to. It also configures deployment parameters such as timeout and memory for that service.
This is the node/service.json from the 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 settings, it's possible to export handler functions in the
node/index.tsfile. Most of the fields inservice.jsonare 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 an event handler in 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 | Number of workers to spawn for that service in production. (Max: 4) |
It's also possible to export GraphQL services using the
graphqlbuilder. You can checkvtex.graphql-exampleto see how it's done.