Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (25 sloc) 1.01 KB

Directives and Validation

Pattern matching is an easy and reliable way to handle requests that conform to expected criteria, but what about the requests that don't? Typically, they fall through to a 404 handler. While this behavior is logical enough from the perspective of a service's programming, clients of the service might reasonably assume that they've supplied the wrong path instead of, as in a previous example, @ref:an invalid parameter.

With enough fallback cases and nested match expressions, you could program whatever logic you want — including descriptive error handling. But that approach sacrifices the simplicity and readability that made pattern matching attractive in the first place.

Fortunately, there is another way. With directives you can express request criteria concisely, and scrupulously handle errors too.

@@@ index

@@@