Basic

A route is a registration

The path is not a string in a condition, it is a name given to a function. The registration is what makes the set of routes a list rather than a search.

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 registered routes

1

Write the registrations

printf 'GET /health\nPOST /api/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 registrations, and the method is part of each name.
2

Attempt the wrong method

printf 'GET /api/ping\n' | grep -c -f - /tmp/r.txt

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

What it prints
0. The name is not in the list, which is a 405 rather than a 404.
3

Write the list as the contract

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 registered route
1 The path and method are named
↓
2 The function is registered against them
↓
3 The list is printed at start
↓
4 A miss becomes a 404 with the list as proof
Why this works
Why the routes are written in one file

One file is one read. Routes spread across modules is a contract that no single read can check.

The one thing to check before logic

The list. A route in the list that has no function is a route that will fail at import.

Examples

The list is the truth

A route that is not registered does not exist. The list is what says so, and the list can be printed.

Methods are part of the name

A path with the wrong method is a different route. The 405 is the answer that names the mistake.

Why the decorator is a risk

A decorator that registers hides the registration. The hidden form is the form that cannot be printed.

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.

← The app is one object
Previous Lesson
The app is one object
Next Lesson
The request is an object with rules
The request is an object with rules →