Lesson 5. Path and Query
Example 5.1. Path parameters
JSIGHT 0.3
 
GET /cats/{id} // Get a cat by its id.
  Path
  {
    "id": 123 // {min: 0}
  }
 
  200 @cat
 
#-------------- Types-----------------
TYPE @cat
{
  "id": 123,
  "name": "Tom"
}
In the given example, on line 4, the directive Path is specified, with the help of which, the
requirements for the path parameters are set. This example describes the path parameter id (line
6).
The directive Path can be used inside directives-http-methods (GET, POST, PUT etc.), as well
as inside the directive URL, for example:
JSIGHT 0.3
URL /cats/{id}
  Path
  {
    "id": 123 // {min: 0}
  }
 
  GET // Get a cat by its id.
    200 @cat
#-------------- Types-----------------
TYPE @cat
{
    "id"  : 123,
    "name": "Tom"
}
info
For more information about this topic, see:
Example 5.2. Directive Query
JSIGHT 0.3
 
GET /cats
 
  Query "page=1&per_page=50"
    {
      "page": 1,
      "per_page": 50 // {optional: true}
    }
 
  200 [@cat]
#-------------- Types-----------------
TYPE @cat
{
    "id"  : 123,
    "name": "Tom"
}
In the given example, the directive Query sets the requirements for the query string's content.
Query string parameters are described in the body of the directive Query using the JSight schema
(lines 6–9).
info
For more information about this topic, see: