helloworld

The helloworld.example microservice is the canonical minimum Microbus example: a single web endpoint that returns the static string Hello, World!. It exists to make the framework’s basic structure visible without any application noise — no configs, no downstream calls, no state.

Try It

With the examples app running:

http://localhost:8080/helloworld.example/hello-worldHello, World!

Generation Prompts

The whole example is produced from two coding-agent prompts:

Create a new microservice helloworld in @exampleservices/helloworld/ with the hostname “helloworld”.
Create a web endpoint that prints “Hello, World!”

The first prompt produces the package skeleton — service.go, the generated intermediate.go, the helloworldapi client package, manifest.yaml, the test scaffolding, and the embedded resources/ directory. The second prompt adds the single endpoint.

Code Walkthrough

Source: exampleservices/helloworld/service.go.

The Service struct holds nothing but the framework’s generated *Intermediate:

type Service struct {
    *Intermediate // IMPORTANT: Do not remove
}

OnStartup and OnShutdown are empty — present as overridable hooks but doing nothing here. A real microservice would initialize caches, subscribe to events, or validate config in them.

Wiring (intermediate.go)

The constructor and the one endpoint subscription, from the generated intermediate.go:

func NewService() *Service {
    svc := &Service{}
    svc.Intermediate = NewIntermediate(svc)
    return svc
}
svc.Subscribe(
    "HelloWorld", svc.HelloWorld,
    sub.At(helloworldapi.HelloWorld.Method, helloworldapi.HelloWorld.Route),
    sub.Description(`HelloWorld prints the classic greeting.`),
    sub.Web(),
)

sub.Web() marks the handler as taking the raw http.ResponseWriter / *http.Request rather than parsed Go arguments — appropriate for serving a plain-text response. The route metadata (helloworldapi.HelloWorld.Method, .Route) is generated from manifest.yaml.

HelloWorld

func (svc *Service) HelloWorld(w http.ResponseWriter, r *http.Request) (err error) {
    w.Write([]byte("Hello, World!"))
    return nil
}

Nothing more to it. The framework handles routing, the HTTP ingress proxy makes the endpoint reachable at /helloworld.example/hello-world, and the handler writes its body and returns.

See Also

  • Building Your First Microservice — the recommended starting tutorial; uses helloworld as the destination.
  • Calculator example — adds functional endpoints, custom types, and metrics on top of this skeleton.
  • Hello example — the same skeleton extended across many endpoint patterns (configs, tickers, service-to-service calls, embedded resources, localization).