Skip to main content

Lesson 2. User types

Example 2.1. Declaring a user type

JSIGHT 0.3

GET /cats/{id} // Get a cat by its id.
200 @cat

TYPE @cat // Type “Cat”.
{
"id" : 123,
"name": "Tom"
}

In this example, on line 6, we used the directive TYPE to declare a user type @cat. We have described the schema of this type in the body of the directive TYPE (lines 7–10).

The type @cat can now be used in other parts of the project. We specified the type @cat in the parameter of the directive 200 (line 4). This means that the response with the code 200 to the GET /cats/{id} request must return a structure corresponding to the type @cat.

Names of user types must always start with the character @.