liveBook · Manning

Canonical form

As explained in API Design Patterns

A canonical form is the single standardized representation selected as the definitive form of equivalent values or inputs.

A canonical form is one standardized representation for equivalent values or inputs. It makes comparisons, identifiers, and request signatures consistent even when inputs vary. section 30.3.4 section 6.3.3

Use canonicalization deliberately:

  • Assemble request components in a fixed order, lowercase header names, and separate key-value pairs with newlines. section 30.3.4
  • Keep the canonical representation strict while allowing decoding to accommodate case mistakes, confused characters, and optional hyphens. section 6.3.3
  • Hash large request bodies into a Base64 Digest header instead of placing the complete body in the fingerprint. section 30.3.4

Signing an HTTP request

A PATCH request to /chatRooms/1 can canonicalize its target, host, date, and SHA-256 digest as newline-separated fields, producing a stable payload for a digital signature. section 30.3.4

Table 30.1 Components necessary for fingerprinting a HTTP request (view table figure)

Field

Location

Description

Method

First line

Action of the request

Path

First line

Target resource of the request

Host

HTTP header

The destination host for the request

Content

HTTP body

Payload of the request

Date

HTTP header

When the request is created

Review the request fields that contribute to a canonical fingerprint. section 30.3.4

How API Design Patterns covers it

How deep it goes
Explains ordering, casing, hashing, and tolerant decoding through concrete implementations, stopping short of signature computation.
Examples
Uses a signed PATCH request and a hyphenated Crockford’s Base32 identifier.
What it assumes
Assumes HTTP methods, paths, headers, bodies, hashing, and encoding; teaches how to combine them into canonical representations.
What you can do after
Build it from scratch by assembling deterministic request fingerprints and defining tolerant identifier decoding.
How it connects
Connects canonical form with HTTP requests, digital signatures, hash digests, identifiers, and Base32 encoding.

Also explained in

Compare how 2 books explain canonical form →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.