Additional annotations

To pass an ID to a route, as is common during the display of a single accommodation, the code would be as follows:

/**
* Display the specified resource.
* @Get("/accommodation/{id}")
*/

This DocBlock annotation would be placed above the function inside the class, which is similar to the previous example.

To limit the ID to one or more digits, an @Where annotation can be used as follows:

@Where({"id": "d+"})

Both the annotations are combined together as shown in the following code:

/**
 * Display the specified resource.
 * @Get("/accommodation/{id}")
 * @Where({"id": "d+"})
 */

To add middleware to the example, which limits the request to only authenticated users, the @Middleware annotation may be used:

/**
 * Display the specified resource.
 * @Get("/accommodation/{id}")
 * @Where({"id": "d+"})
 * @Middleware("auth")
 */

HTTP verbs

The following is a list of the various HTTP verbs that can use annotations, that mirror RESTful standards:

  • @Delete: This verb deletes a resource.
  • @Get: This verb displays a resource or resources.
  • @Options: This verb displays a list of options.
  • @Patch: This verb modifies an attribute or attributes of a resource.
  • @Post: This verb creates a new resource.
  • @Put: This verb modifies a resource.

Other annotations

There are additional annotations that also may be used in controllers. The annotations are as follows:

  • @Any: This responds to any HTTP request.
  • @Controller: This creates a controller for a resource.
  • @Middleware: This adds middleware to a resource.
  • @Route: This enables a route.
  • @Where: This limits requests based on certain criteria.
  • @Resource: This enables a resource.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset