← all lessons

Lesson 10

Capstone: the Weather service

Capstone: the Weather service

This is the canonical example from Smithy’s own quickstart. It pulls together everything you’ve learned: a service, resources with identifiers, lifecycle operations, @readonly, target elision, and an error.

The starter already wires up the Weather service, the City resource, and the CityId string. Your job is to fill in the operations and the error so the model assembles.

What you’re building

  • GetCity — the resource’s read. It’s @readonly; its input uses target elision to pull cityId from the resource (input := for City { @required $cityId }); its output has a @required name: String. It can fail with NoSuchResource.
  • GetCurrentTime — a standalone @readonly operation on the service that returns a @required time: Timestamp.
  • NoSuchResource — a client error structure.

A worked skeleton of the pieces:

@readonly
operation GetCity {
    input := for City {
        @required
        $cityId
    }

    output := {
        @required
        name: String
    }

    errors: [
        NoSuchResource
    ]
}

@readonly
operation GetCurrentTime {
    output := {
        @required
        time: Timestamp
    }
}

@error("client")
structure NoSuchResource {
    @required
    message: String
}

Going further

The real Weather model adds a nested Forecast resource, a @paginated ListCities, resource properties (like coordinates), and @references between shapes. Once your model compiles, try extending it — the editor will tell you the moment something doesn’t line up.

Your turn