Skip to main content

Lesson 3. Resource tree

Example 3.1. Simplest resource tree

JSIGHT 0.3

#------------ Resources-------------
GET /cats // Get the list of all cats.
200
[@cat]

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

DELETE /cats/{id} // Delete a cat by its id.
200
"Cat is deleted"

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

In the given example, we described the simplest resource tree consisting of two resources:

  • /cats
  • /cats/{id}

The resource /cats can be accessed using the method GET (line 4).

The resource /cats/{id} can be accessed using methods GET and DELETE (lines 8 and 12).

info

For more information about this topic, see:

Example 3.2. Directive URL

JSIGHT 0.3

#------------ Resources-------------
URL /cats
GET // Get the list of all cats.
200
[@cat]

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

DELETE // Delete a cat by its id.
200
"Cat is deleted"

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

In the given example, we described the same API as in the previous example, but we used the directive URL to group methods by resources.

Line 4 declares the directive URL /cats which groups the methods of the branch of resources /cats together (in this example, this branch has only one method GET on line 5).

Line 9 declares the directive URL /cats/{id} which groups the methods of the branch of resources /cats/{id} together (method GET on line 10 and method DELETE on line 14).