My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Thursday, January 30, 2020

Json schema validation for Api Gateway request

Amazon’s API Gateway provides the facilities to map an incoming request’s payload to match the required format of an integration backend. It uses the concept of “models” and “mapping templates” to specify the mapping between the client payload and the server payload.
A model defines the structure of the incoming payload using JSON Schema. The model is an optional, but not required, piece of API Gateway. By providing a model, you make it easier to define the upcoming mapping template that actually does the transformation between the client and server.
For example, we can define a incoming Player model using the following JSON payload.
{
    "id": "AJamal",
    "alias": "Aha Jamal",
    "displayName": "Anwar jamal Faiz",
    "photoUrl": "https://api.example.com/player/AJamal/avatar.png"
}


JSON Schema is a vocabulary allowing you validate JSON documents. The particular JSON payload being validated is called an instance, and the document describing what a valid payload looks like is called the schema.
JSON Schema is used to describe a JSON document, so it helps to understand what, exactly, a JSON document is composed of these primitives:
  • objects: {"field1": "value1", "field2": "value2"}
  • arrays: ["first", "second", "third"]
  • numbers: 42 or 3.1415926
  • strings: "Lorem ipsum dolor sit amet"
  • booleans: true or false
  • null: null
The responsibility of JSON Schema is to describe a JSON document built from the these primitives.
JSON Schema is itself specified using JSON with predefined semantics for keywords and values. Going back to our Player example, we can specify the JSON Schema for the incoming document as follows:
{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "id": { "type": "string" },
        "alias": { "type": "string" },
        "displayName": { "type": "string" },
        "photoUrl": { "type": "string" }
    }
}
This JSON Schema follows the Draft 4 specification and simply declares the types expected for each field in the request. 

For more details consult this guide.

No comments:

Post a Comment