Route Metadata

The route describes the path component of the URL that will be used to address your end point.  It does not describe any query parameters or request body parameters.  The route object can have the following properties:

Route object properties

Property Name

Value 

Comments

httpMethod A string whose value is either GET, POST, PUT, PATCH or DELETE.  

Describes the HTTP Method that should be used to invoke the end point.

segments An object whose properties are the name of the segment, and values are segment objects.  A route needs one or more segments.

Segment object properties

Property Name

Value 

Comments

isLiteral boolean

Determines if this route segment should be a literal value or not. When it is a literal then the framework will expect to find the name of the segment object in the path. When it is not a literal, the framework will allow any value that matches the type setting for the segment object.

type string The type of the segment. Literal segments should be strings. Non literal segments should be the type you expect in the URL path. Valid types are: string, long, int, decimal, float, double, bool. Typically only string and long are used. Non literal segments should have their type match the same property on the input entity definition.

Let's look at a few examples:

Sample route block - only literals
{
  "endpoints": {              
    "ExamplesGetAllProducts": {
      "route": {
        "httpMethod": "GET",
        "segments": {
          "examples": {
            "isLiteral": true,
            "type": "string"
          },
          "products": {
            "isLiteral": true,
            "type": "string"
          }
        }
      }
      //remaining metadata omitted
    }
  }
}

The above example only has literals for segments, so it would create a GET end point at /examples/product

Sample route block - with non-literals
{
  "endpoints": {              
    "ExamplesGetSingleProduct": {
      "route": {
        "httpMethod": "GET",
        "segments": {
          "examples": {
            "isLiteral": true,
            "type": "string"
          },
          "products": {
            "isLiteral": true,
            "type": "string"
          },
          "productId" : {
             "isLiteral" : false,
             "type" : "long"
          }     
        }
      }
      //remaining metadata omitted
    }
  }
}

The above example has a non-literal segment named productId that is a long.  You could issue a GET to /examples/products/1 or /example/products/20213, but you could not issue a GET to /examples/products/SampcoHat.

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.