Skip to main content

Lesson 9. Magic directive MACRO

Example 9.1. Directives MACRO and PASTE


GET /cats // Get all cats
200 [@cat]
PASTE @errorResponses

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

TYPE @cat // Type “Cat”
"id" : 1,
"name": "Tom"

MACRO @errorResponses
400 any
401 any
405 any
500 any

The provided example demonstrates how to use the directive MACRO. This directive allows you to name a group of directives and then reuse them throughout the project with the directive PASTE.

In our example, a set of directives-responses @errorResponses is declared (lines 19–26). This set is pasted in the requests GET /cats (line 5) and GET /cats/{id} (line 10).