Lesson 12
Challenge: match this HTTP request
Challenge: match this HTTP request
Every other lesson went model → protocol. This one runs the other way. Below is a
real HTTP exchange. Your job: write the Smithy operation whose @http bindings
would produce exactly this request and response.
This is the everyday job of an API modeler — you have an endpoint that already
exists (or a design someone sketched as a curl), and you need to capture it
faithfully in the model.
The exchange
A request that searches a city’s points of interest, filtered by category, with a trace header:
GET /cities/paris/poi?category=museum HTTP/1.1
X-Request-Id: 7c1f...
HTTP/1.1 200 OK
Content-Type: application/json
{ "results": ["Louvre", "Orsay"] }
Reading it off
Work through the request piece by piece — each part maps to one binding:
| In the exchange | Smithy binding |
|---|---|
GET … → 200 | @http(method: "GET", uri: "/cities/{cityId}/poi", code: 200) |
/cities/**paris**/poi | cityId is a @required @httpLabel |
?category=museum | category is @httpQuery("category") |
X-Request-Id: header | requestId is @httpHeader("X-Request-Id") |
{ "results": [...] } body | an output member results (a list), left in the body |
Your turn
Model the SearchPoi operation so it matches the exchange above. The checks read
the request back out of your model: the exact @http value, the label, the
query, the header, and the body list.
Tip: the output’s results member has no binding trait, so it stays in the
JSON body — exactly the { "results": [...] } you see in the response.