Basic

The server is in the standard library

There is no framework to choose. The standard library has a server, and the choice that remains is what the server is given, which is a set of decisions rather than a dependency.

What you will see

2. The contract is a file, and the file is what review argues with.

About 1 min of reading

Try It

Print the route table

1

Write the table

printf '/health health\n/api/v1/ping ping\n' > /tmp/r.txt; wc -l < /tmp/r.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. Two routes is the whole contract of the server.
2

Ask for a route not in the table

printf '/api/v2/ping\n' | grep -f - /tmp/r.txt; echo $?

Before you run it, say out loud what it will print. Then open the answer.

What it prints
1. A miss is a 404, and the table is what makes the 404 a fact.
3

Write the table as the contract file

cp /tmp/r.txt /tmp/contract.txt; wc -l < /tmp/contract.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. The contract is a file, and the file is what review argues with.

Data Flow

A path to a handler
1 The request arrives with a path
↓
2 The router looks the path up in the table
↓
3 The handler is called with the request
↓
4 The response is written
Why this works
Why the handler signature is the contract

The signature says what a handler may read and write. A framework that hides the signature hides the contract.

The one thing to measure first

The table. A route that is not in the table is a route that does not exist, and the table says so.

Examples

No magic

A handler is a function with a request and a response. Nothing is registered by a macro and nothing is hidden in a base class.

The router is a table

Paths to functions. The table can be printed, and a printed table is a contract.

Why the dependency list stays short

A framework adds a layer between the code and the request. The layer is the thing that drifts on upgrade.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

Next Lesson
A handler is a function
A handler is a function →