Skip to content
weft-sdkPublic

About

Runnable example projects for Weft: TypeScript and Go services that talk over HTTP and Kafka

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Weft

Weft examples

Runnable projects that show Weft working: two services, two languages, one contract.

CI License

Weft  ·  Documentation  ·  Contract language


Orders and notifications

An orders service in TypeScript takes POST /v1/orders, and publishes an order.placed event to Kafka. A notifications service in Go receives it. Neither service knows the other's language: both are generated from one contract, contracts/orders.weft.

flowchart LR
    C["curl"] -- "POST /v1/orders" --> O["<b>orders</b><br>TypeScript · Express"]
    O -- "order.placed" --> K[("Kafka")]
    K -- "order.placed" --> N["<b>notifications</b><br>Go · franz-go"]
Loading
Folder What it is
contracts/ The shared contract: types, the order.placed event and the HTTP routes
typescript-orders/ The orders service: weft.http on Express, weft.kafka on KafkaJS
go-notifications/ The notifications service: weft.kafka on franz-go
docker-compose.yaml A single Kafka broker

Run it

You need Node 22 or later, Go 1.26 or later, and Docker. Start Kafka:

docker compose up -d --wait
export KAFKA_BROKERS=127.0.0.1:9092

In one terminal, the Go service:

cd go-notifications
go run .

In another, the TypeScript service:

cd typescript-orders
npm install
npm start

Place an order:

curl -X POST localhost:3000/v1/orders \
  -H 'content-type: application/json' \
  -d '{"customerId":"c-42","items":[{"sku":"apple","qty":3},{"sku":"pear","qty":1}]}'

The Go service prints the order, with the same typed fields the TypeScript service sent:

order 3b311adf-a4d3-49f3-9301-fad5262c4bae from c-42: 2 items, total 2000 EUR

What to try

  • A wrong body is rejected before your code runs. Send {"customerId": 1} and you get a 400 with a problem details body that names body.customerId.
  • A missing order is a 404 without code. GET /v1/orders/{id} returns Order? in the contract, so returning undefined answers 404.
  • A wrong payload does not compile. In typescript-orders/src/main.ts, publish order.placed with a field missing, and npm run check points at it.
  • Change the contract. Add a field to Order in contracts/orders.weft, run weft gen in both folders, and both services get it.

Regenerate the code

The generated files, typescript-orders/src/weft.gen.ts and go-notifications/weft.gen.go, are checked in. To regenerate them, install the CLI and run weft gen in each folder:

cargo install --git https://github.com/weft-sdk/weft weft-cli --locked
(cd typescript-orders && weft gen)
(cd go-notifications && weft gen)

License

Apache License 2.0.

About

Runnable example projects for Weft: TypeScript and Go services that talk over HTTP and Kafka

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages