Run your first Arc.Go application
You want a command endpoint, not a collection of transport handlers. Arc maps registered commands and queries when you build the application. The Go API supports snapshot and observable HTTP. Start with a unary command here; then use observable queries for live results. Observable generation remains separate tools work.
Run a greeting command
Section titled “Run a greeting command”You need Go 1.26 or later and two terminals. From the repository root, run the hosting example in the first terminal. Leave it running while you send requests from the second terminal:
go run ./examples/hostingThe business model is an ordinary Go type:
type Greet struct { Name string `json:"name" validate:"required"`}
func (c Greet) Handle(_ context.Context) (string, error) { return "Hello, " + c.Name, nil}This excerpt uses context from the standard library. The application registers
Greet.Handle with commands.Register and commands.Handle, then builds and runs
Arc. No separate endpoint-mapping step can be forgotten.
In the second terminal, send a greeting:
curl -H 'Content-Type: application/json' -d '{"name":"Ada"}' http://127.0.0.1:8080/api/greetThe command envelope contains "response":"Hello, Ada". An empty name returns
400. Post the same body to /api/greet/validate to validate without invoking the
handler. When you finish, press Ctrl+C in the server terminal to initiate graceful
shutdown.
Compose your application
Section titled “Compose your application”You have already run the application; no second startup step is needed. To adapt
the sample for your own application, use its composition function below. This
excerpt assumes the model above and imports arc, commands and context:
func run(ctx context.Context) error { builder, err := arc.NewBuilder(arc.Options{}) if err != nil { return err } if err := commands.Register[Greet](builder, commands.Handle(Greet.Handle)); err != nil { return err } app, err := builder.Build() if err != nil { return err } return app.Run(ctx, "127.0.0.1:8080")}You own signals and error reporting. Build validates composition without
starting a listener or activating dependencies. Run starts admission and owns
the server. Continue with hosting and authentication
before exposing private operations beyond loopback.