| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Temporal Web API is a Node.js application that provides a web interface to interact with Temporal workflows. It allows users to start workflows and retrieve their status via HTTP endpoints. This application serves as a bridge between HTTP requests and Temporal's workflow orchestration capabilities.
Clone the repository
git clone https://github.com/yourusername/temporal-web-api.git
cd temporal-web-apiInstall dependencies
npm installEnvironment Variables
Create a .env file in the root directory and set the following environment variables:
# Temporal configuration
TEMPORAL_ADDRESS=localhost:7233
TEMPORAL_NAMESPACE=default
# Server configuration
PORT=5000
# TLS configuration (if applicable)
TEMPORAL_TLS_CRT=path/to/your/certificate.crt
TEMPORAL_TLS_KEY=path/to/your/private.key
# Node environment
NODE_ENV=developmentConfigure Temporal
Ensure that your Temporal server is running and accessible at the address specified in TEMPORAL_ADDRESS.
To start the application in development mode with hot-reloading:
npm run devThis command compiles TypeScript files and starts the server using nodemon and ts-node. The server listens on http://localhost:5000 by default.
Running the Sample Worker
In a separate terminal, start the Temporal worker:
npm run dev:worker-sampleBuild the application:
npm run buildStart the server:
npm startRunning the Sample Worker
In a separate terminal, start the built worker:
npm run start:worker-sampleTo build and run the application using Docker:
Build the Docker image
docker build -t temporal-web-api .Run the Docker container
docker run -p 5000:5000 temporal-web-apiVerify if the service is running by accessing:
GET http://localhost:5000/api/health
Response:
Connection is healthy
To start a workflow, send a POST request to /api/workflow/start with the workflow name and arguments.
Endpoint:
POST http://localhost:5000/api/workflow/start
Headers:
Content-Type: application/jsonBody:
{
"name": "sampleWorkflow",
"args": ["Hello, World!"]
}Sample Request using curl:
curl -X POST http://localhost:5000/api/workflow/start \
-H 'Content-Type: application/json' \
-d '{
"name": "sampleWorkflow",
"args": ["Hello, World!"]
}'Response:
{
"message": "Workflow sampleWorkflow started",
"id": "sampleWorkflow-<uuid>"
}To get the status of a workflow, send a GET request to /api/workflow/status with the id.
Endpoint:
GET http://localhost:5000/api/workflow/status?id=<workflow-id>
Sample Request using curl:
curl http://localhost:5000/api/workflow/status?id=sampleWorkflow-<uuid>Response:
{
"message": "Status of workflow sampleWorkflow-<uuid>",
"result": {
"name": "Hello, World!"
},
"status": "COMPLETED",
"queries": {
"condition": "ok"
}
}temporal-web-api/ ├── src/ │ ├── controllers/ │ │ └── workflowController.ts # Handles workflow API logic │ ├── routers/ │ │ ├── index.ts # Main router │ │ └── workflowRouter.ts # Workflow routes │ ├── services/ │ │ └── temporal.ts # Temporal client and worker connections │ ├── worker/ │ │ └── sample.ts # Sample worker setup │ ├── workflows/ │ │ ├── sample/ │ │ │ ├── activities.ts # Sample activities │ │ │ └── workflows.ts # Sample workflow definitions │ │ └── registry.ts # Workflow registry │ └── index.ts # Express server setup ├── assets/ │ └── sample/ │ ├── start.http # Sample request to start a workflow │ └── status.http # Sample request to get workflow status ├── dist/ # Compiled JavaScript files (after build) ├── .env # Environment variables (not committed) ├── .gitignore ├── Dockerfile ├── package.json ├── tsconfig.json └── README.md
Available NPM scripts:
Licensed under the Apache License, Version 2.0. See the LICENSE file for details.
| Back | FazBrowse Home | New Git URL |