Docs » Documenting your API » Documenting query and URL parameters for an endpoint
Documenting query and URL parameters for an
endpoint
Specifying query parameters
To describe query parameters for your endpoint, use the gaueryraran annotation on the method
handling it.
The gqueryParan annotation takes the name of the parameter, an optional type, an optional
“required” label, and a description.
If you don't specify a type, Scribe will assume it’s string .Se( _@ documentation on body
parameters for a list of valid types.
Here's an example:
a
* @queryParam sort string Field to sort by. Defaults to ‘id’
= gqueryParam Fields required Conna-separated List of fields to include in the response. Example:
title, published at, is public
* @queryParam filters[published_at] Filter by date published.
* GqueryParam Filters{is public] integer Filter by whether a post is public or not. Example: 1
y
public function listPosts()
t
“
y
The query parameters will be included in the generated documentation text and example requests:Query Parameters
sort string optional
Field to sort by. Defaults to ‘id’.
fields string
Comma-separated list of fields to include in the response.
filters[published_at] string optional
Filter by date published.
filters[is_public] integer optional
Filter by whether a post is public or not.
If you need to handle array/object parameters, you can use the same conventions as for body
parameters:
uo
* @queryParam sort string Field to sort by. Defaults to ‘id’
* @queryParam fields string[] required Conma-separated List of fields to include in the response.
Example: title,published_at, is_public
= @queryParam filters object Fields to filter by
GqueryParan filters.publishedat Filter by date put
* GqueryPoram Filters.is_public integer Filter by whi
"
ed
ier a post is public or not. Example: 1You should avoid using query parameters that are arrays or objects, because [there isn’t a
standardised format for handling them)(https: /stackoverflow.com/a/9547490/7370522).
If you're using a FormRequest in your controller, you can also add the gqueryearan annotation
there instead, and Scribe will fetch it.
ao
* @queryParam user_id required The id of the user.
"7
class CreatePostkequest extends \I1luninate\Foundation\Http\FormRequest
y
// in your controller...
public function createPost(CreatePostRequest $request)
{
7
Specifying example values
By default, Scribe will generate a random value for each parameter, to be used in the example
requests and response calls. If you'd like to use a specific example value, you can do so by adding
Example: your-example-here to the end of your description.
You can exclude a particular parameter from the generated examples by ending with No-
example instead. The parameter will still be included in the text of the documentation, but it
won't be included in response calls or shown in the example requests.
For instance:a
* @queryParam sort Field to sort by. Defaults to Example: published at
* GqueryParam fields required Conna-separated fields to include in the response. Example.
title, published at, id
* GqueryParam filters[published at] Filter by date published. No-example
* GqueryParam filters[title] Filter by title. No-exanple
v
Describing URL parameters
To describe parameters in the URL, use the @uriparan annotation. For instance,
you defined
your Laravel route like this:
Route: :get(*/post/{S¢)/(Lang?)");
you can use this annotation to describe the is and iang parameters as shown below. The
annotation takes the name of the parameter, an optional type, an optional "required" label, and
then its description. Like with gqueryParans , a random value will be generated, but you can specify
the value to be used in examples and response calls using the exanple: syntax.
If you don't specify a type, Scribe will assume it’s. string . Valid types are string, integer , and
number .
ye
* @urLParan id integer required The 1D of the post
* @urLParam Lang The Language. Example: en
v
public function ¢
sePost()
“uIf you want Scribe to omit an optional parameter (lang in our example) in requests and
response calls, specify No-exampie for the parameter.
public function getPost()
“
ec at ts