Validation in the API world means checking if the data send is good or not. You never can entirely rely on having only a client-side validation. Because you don’t know what’s happening on the client, you can’t trust the data you receive. Even if you have a private API, someone could still send you invalid requests.

Server-side validation implied checking multiple things :

  • what are the expected properties
  • does they have the good format/type
  • is the property required

Json schema

The  JSON Schema is a way to describe any instance of JSON data, like the ones found in our HTTP request or response.

The keyword type will restrict your property to a certain type. There is several possible values :

  • string
  • number
  • object
  • array
  • boolean
  • null

#python #validation #flask #json #api

Server validation in Flask API with JSON schema
12.95 GEEK