Skip to content

Chapter 2 - Validating Requests#1

Open
clairefro wants to merge 1 commit intochapter-1-crud-apifrom
chapter-2-validating-requests
Open

Chapter 2 - Validating Requests#1
clairefro wants to merge 1 commit intochapter-1-crud-apifrom
chapter-2-validating-requests

Conversation

@clairefro
Copy link
Contributor

We need to make sure our API returns a 400 Bad Request error if a client makes a crazy request that doesn't match our schema, like:

POST /restaurants
with a Body of { "someCrazyProperty": "nonsense"}

We can enforce our OpenAPI schema on our fastify API using the plugin library fastify-openapi-glue

This library identifies each of our paths by their operationId in our schema.yaml, and converts them into fastify routes with the correct request methods. Better yet, the generated routes check each request to that route and make sure it fits our schema, or else it sends an error to the client!

API First makes life easy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant