The legacy API and the screen that uses it
This is the free lesson
Next: One schema in front of the old API
The rest of this course is part of Pro, together with every other course and the ones added later.
$25 a month billed yearly, or $29 month to month
Until 30 November: $210 for the first year, or $14.50 for the first month, with code LAUNCH.
A free account keeps your progress across devices. The paid lessons need Pro.
Code Snippets
docker run -d --name petclinic --label course=graphql-mcp --platform linux/amd64 \
-p 127.0.0.1:9966:9966 springcommunity/spring-petclinic-rest:4.0.2
API=http://127.0.0.1:9966/petclinic/api
until curl -s -o /dev/null $API/vets; do sleep 2; done
docker ps --filter label=course=graphql-mcp --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'
curl -s $API/owners | jq '.[0]'
curl -s $API/owners | wc -c
curl -s $API/owners | jq -c '[.[] | {firstName, lastName, city, pets: [.pets[].name]}]' | wc -c
curl -s $API/owners/6 | wc -c
curl -s -o /dev/null -w '%{http_code}\n' $API/owners/6/pets
curl -s $API/vets | wc -cIn this video you'll run an old web service, and measure how much of each answer a screen really uses. Spring PetClinic REST stands in for the old system: a REST API, an application programming interface with one web address per resource, in a container. With curl I call it as a screen would. With jq, a processor for JSON, the data format of the answers, I keep only what the screen shows, and compare the sizes. In this lesson you will run the PetClinic REST API in Docker, measure what a list screen gets against what it shows, and count the calls a screen that needs owners and vets makes. Before you start, you need Docker, for example with Colima, and jq. Spring PetClinic REST 4.0.2 is published for Intel processors only, so I ask for the amd64 platform, and Docker runs it emulated on Apple silicon. It starts slower, and that is fine. The port is published on one two seven dot zero dot zero dot one only, and a label marks the container as this demo's. The loop waits for the API. Emulated, that takes a while, so I speed up the video. This API is the legacy estate. The first answer to old APIs is a rewrite. In his talk at the Amsterdam Java User Group, Željko Kozina answered that with Martin Fowler: the only thing a Big Bang rewrite guarantees is a Big Bang. The second answer, one tool for every endpoint, fails too: the more tools an agent sees, the worse it chooses. The screens are a better guide. Someone already decided what each screen fetches and shows. The API is up. An owners list screen shows each owner's name, city and pets. Here is the first owner, as the API returns it. Every field: the address, the telephone, ids, the pet's birth date and type, and its list of visits. Now the size of the whole list, in bytes. Next, I let jq keep only what the screen shows: names, city, and pet names. The list costs 2,919 bytes, and the screen shows 805 of them, less than a third. A screen throws the rest away. An agent cannot: every byte goes into its context. One owner is one call. Owner 6 comes back with the pets, their types and their visits, in one answer. 589 bytes. In his talk, Željko showed the owner page of his PetClinic making five requests: the owner, the owner's pets, the pet types, and the visits of each pet. This version of the API works differently. Five hundred: this API has no endpoint that reads an owner's pets. The owner comes back with everything in one call, so here the cost is over-fetching, not the number of requests. A screen that books a visit needs the owner and the vets. That is a second call. 533 bytes more, every vet with every specialty. Two calls, 1,122 bytes with every field of both, for one screen. That is what the screens of this API cost, and what a facade designed from them can cut. In this lesson you learned that a screen shows a fraction of what the API sends: 2,919 bytes for the owners list, of which the screen shows 805. And that a screen combining owners and vets needs two calls, with every field of both.