Back to LOC CLI Guidebook
Setup LOC CLI Environment
LOC CLI Installation
LOC CLI Commands
Local Simple Runtime Execution
In this tutorial, we are going to create a simple LOC data process using TypeScript.
This data process would receive a POST request with JSON data, which contains a name
field. It would return a response including this message:
See the setup guide for how to prepare your local LOC CLI environment, including getting a .yaml profile file and install Node.js. We also assume you are have renamed your LOC CLI to loc.exe
.
You can also open the LOC CLI workspace directory (for example, /FST
) in VS Code (File -> Open Folder…).
In your LOC CLI workspace root directory (FST
in our example), create a new data process with
You should see a new project
Then open the LOC CLI root directory (not the project directory) as workspace in your VS Code.
LOC data processes will be executed in a Deno runtime so you don't need to install TypeScript on your machine.
A LOC CLI TypeScript project requires dependency packages for type checks and deployment rolling-up.
Since fstnetwork/saffron-sdk
is currently a private Github repository, please contact FST Network for granting you access.
(Windows)
(macOS/Linux)
First look at the config.yaml
in the project directory:
This file contains key information of the data process, including time out and the file name/order of generic logics. For now we won't change anything here, but keep in mind you can configure them as you like.
The 1st generic reads the name
field from JSON data, convert it into Unicode string and store it in the data process' session storage:
See Agent List for reference of LOC agents.
While using TypeScript, it is necessary to check what's in the ctx.payload
(using so-called type guards) to avoid type errors. It would be ctx.payload.http.body
in this example, but the TypeScript compiler won't know that.
The 2nd generic logic reads the name
from session storage and send an event.
The aggregator logic also reads the name
from sessoin storage and send a response to the caller.
See Getting Started - Hello World (JavaScript) for more details.
hello-world-ts
using profile example
:api-route-config.yaml
(be mindful of the project path):hello-world-ts
with its API route at the same time:./loc deploy hello-world-ts -ts -ar
replaces the API route but will still upload a new data process. You need to manually delete the older one(s) in order to release unused resources.
LOC CLI