Page 1 of 63 - Express API Validation
Page 1 of 63
Table of Contents
Preface
What you're going to learn
What you'll need to get the most from this book
Code examples
Get in touch
Feedback
Spotted a mistake?
Reviews
Part 1: Doing things the Express way
The middleware pattern
Middleware syntax
The two types of middleware
Plain middleware
Error handling middleware
Using middleware
At the route level
At the router level
At the application level
Middleware in a validation strategy
Page 2 of 63
Request body parsing
Request validation
Sending an error response
Summary
Part 2: Validating requests
The JSON Schema speci cation
Ajv (Another JSON Schema Validator)
Learning JSON Schema
Understanding JSON Schema
JSON Schema Cheat Sheet
JSON Schema speci cations
Why use JSON Schema and not validation library X?
No library, framework or language lock-in
Move between Node.js frameworks, or even languages, and
take your schemas with you
Active and supportive community
JSON Schema is on a path to becoming a standard
Sidenote: JSON (JavaScript Object Notation) vs JavaScript objects
Create a validation pipeline with JSON Schema
Parsing a JSON request body in Express
Body parsing in older versions of Express
Page 3 of 63
De ning JSON schemas in Node.js
Integrating Ajv into your Express application
Using a JSON schema to validate a response body
Validating other request properties
Summary
Part 3: Error responses
Introducing the 'Problem Details for HTTP APIs' speci cation
Problem types and Problem details objects
Example problem details response
More details, clearer problems
Breakdown of a problem details object
Sending validation errors in problem details responses
De ne problem types and map them to JavaScript error
classes
Look up the problem details for an error
Send validation errors in a problem details response
Summary
Part 4: Putting it all together
Example Express API application
Example requests and responses
Request body with missing 'last_name' property
Page 4 of 63
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.