documenting-endpoint-metadata.md 2.1 KB

Specifying metadata about an endpoint

Endpoint title and description

To set an endpoint's title and description, just write in the method's docblock. The first paragraph will be used as the title, the rest as the description. Custom formatting (such as <aside> tags) is also supported (see the Pastel docs).

For instance, this:

    /**
     * Add a word to the list.
     * This endpoint allows you to add a word to the list. It's a really useful endpoint,
     * and you should play around with it for a bit.
     * <aside class="notice">We mean it; you really should.😕</aside>
     */
    public function store(Request $request)
    {
        //...
    }

becomes:

Grouping endpoints

All endpoints are grouped for easy navigation.

To add all endpoints in a controller to a group, use @group in the controller docblock, followed by the group's title. You can also add a description below the group.

.. Tip:: 
You can also specify an `@group` on a single method to override the group defined at the controller level.
/**
 * @group User management
 *
 * APIs for managing users
 */
class UserController extends Controller
{

	/**
	 * Create a user.
	 */
	 public function createUser()
	 {

	 }
	 
	/**
     * Change a user's password.
     * 
	 * @group Account management
	 */
	 public function changePassword()
	 {

	 }
}

Grouping endpoints is optional. Any endpoints not in a group will be placed in a default group, "Endpoints".

Indicating authentication status

You can use the @authenticated annotation on a method to indicate if the endpoint is authenticated. A "Requires authentication" badge will be added to that route in the generated documentation.

.. Tip:: If all the routes in a controller are authenticated, you can specify `@authenticated` in the controller doc block instead. 
    /**
     * Create a user
     * This endpoint lets you create a user.
     * @authenticated
     *
     */
     public function create()
     {    
     }