Skip to content

Commit f5dab0a

Browse files
committed
Update README: pagination and query parameters
Document that pagination default limit does not apply to DELETE requests, and state which methods are supported by different URL query-string parameters.
1 parent e93caf6 commit f5dab0a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ The `resource.Conf` type has the following customizable properties:
667667
| Property | Description
668668
| ------------------------ | -------------
669669
| `AllowedModes` | A list of `resource.Mode` allowed for the resource.
670-
| `PaginationDefaultLimit` | If set, pagination is enabled by default with a number of item per page defined here.
670+
| `PaginationDefaultLimit` | If set, pagination is enabled for list requests by default with the number of item per page as defined here. Note that the default ony applies to list (GET) requests, i.e. it does _not_ apply for clear (DELETE) requests.
671671
| `ForceTotal` | Control the behavior of the computation of `X-Total` header and the `total` query-string parameter. See `resource.ForceTotalMode` for available options.
672672

673673
### Modes
@@ -802,7 +802,7 @@ post = schema.Schema{
802802

803803
## Filtering
804804

805-
To filter resources, you use the `filter` query-string parameter. The format of the parameter is inspired the [MongoDB query format](http://docs.mongodb.org/manual/tutorial/query-documents/). The `filter` parameter can be used with `GET` and `DELETE` methods on collection URLs.
805+
To filter resources, you use the `filter` query-string parameter. The format of the parameter is inspired the [MongoDB query format](http://docs.mongodb.org/manual/tutorial/query-documents/). The `filter` parameter can be used with `GET` and `DELETE` methods on resource URLs.
806806

807807
To use a resource field with the `filter` parameter, the field must be defined on the resource and the `Filterable` field property must be set to `true`. You may want to ensure the backend database has this field indexed when enabled.
808808

@@ -885,7 +885,7 @@ An error of `ErrNotImplemented` will be returned for those storage backends whic
885885

886886
## Sorting
887887

888-
Sorting of resource items is defined through the `sort` query-string parameter. The `sort` value is a list of resource's fields separated by comas (`,`). To invert a field's sort, you can prefix its name with a minus (`-`) character.
888+
Sorting of resource items is defined through the `sort` query-string parameter. The `sort` value is a list of resource's fields separated by comas (`,`). To invert a field's sort, you can prefix its name with a minus (`-`) character. The `sort` parameter can be used with `GET` and `DELETE` methods on resource URLs.
889889

890890
To use a resource field with the `sort` parameter, the field must be defined on the resource and the `Sortable` field property must be set to `true`. You may want to ensure the backend database has this field indexed when enabled.
891891

@@ -895,9 +895,9 @@ Here we sort the result by ascending quantity and descending date:
895895

896896
## Field Selection
897897

898-
REST APIs tend to grow over time. Resources get more and more fields to fulfill the needs for new features. But each time fields are added, all existing API clients automatically gets the additional cost. This tend to lead to huge wast of bandwidth and added latency due to the transfer of unnecessary data.
898+
REST APIs tend to grow over time. Resources get more and more fields to fulfill the needs for new features. But each time fields are added, all existing API clients automatically gets the additional cost. This tend to lead to huge wast of bandwidth and added latency due to the transfer of unnecessary data. To workaround this, the `field` parameter can be used to minimize and customize the response body from requests with a `GET`, `PATCH` or `PUT` method on resource URLs.
899899

900-
To workaround this issue, REST Layer provides a powerful fields selection (also named projection) system. If you provide the `fields` parameter with a list of fields for the resource you are interested in separated by comas, only those fields will be returned in the document:
900+
REST Layer provides a powerful fields selection (also named projection) system. If you provide the `fields` parameter with a list of fields for the resource you are interested in separated by comas, only those fields will be returned in the document:
901901

902902
```http
903903
$ http -b :8080/api/users/ar6eimekj5lfktka9mt0 fields=='id,name'
@@ -1042,15 +1042,13 @@ Such request can quickly generate a lot of queries on the storage handler. To en
10421042

10431043
## Pagination
10441044

1045-
Pagination is supported on collection URLs using `page` and `limit` query-string parameters. If you don't define a default pagination limit using `PaginationDefaultLimit` resource configuration parameter, the resource won't be paginated until you provide the `limit` query-string parameter.
1045+
Pagination is supported on collection URLs using the `page` and `limit` query-string parameters, and can be used for resource list view URLs with request method `GET` and `DELETE`. If you don't define a default pagination limit using `PaginationDefaultLimit` resource configuration parameter, the resource won't be paginated for list `GET` requests until you provide the `limit` query-string parameter. The `PaginationDefaultLimit` does not apply to list `DELETE` requests, but the `limit` and `page` parameters may still be used to delete a subset of items.
10461046

10471047
If your collections are large enough, failing to define a reasonable `PaginationDefaultLimit` parameter may quickly render your API unusable.
10481048

10491049
## Skipping
10501050

1051-
Skipping of resource items is defined through the `skip` query-string parameter. The `skip` value is a positive integer defining the number of items to skip when querying for items.
1052-
1053-
To use a resource field with the `skip` parameter, the field must be defined on the resource.
1051+
Skipping of resource items is defined through the `skip` query-string parameter. The `skip` value is a positive integer defining the number of items to skip when querying for items, and can be applied for requests with method `GET` or `DELETE`.
10541052

10551053
Skip the first 10 items of the result:
10561054

@@ -1068,7 +1066,7 @@ Show the first 2 elements:
10681066

10691067
Paginate the rest of the list:
10701068

1071-
/posts?skip=2&page=1&limit=10
1069+
/posts?skip=2&page=1&limit=10
10721070

10731071
## Authentication and Authorization
10741072

0 commit comments

Comments
 (0)