Skip to content

Commit

Permalink
Add a paragraph that describes how to filter products via API
Browse files Browse the repository at this point in the history
Into the top level "wiki-style" REST API documentation section.
  • Loading branch information
kennyadsl committed Jul 6, 2021
1 parent 7c3741c commit a139faf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions api/openapi/main.hub.yml
Expand Up @@ -38,11 +38,11 @@ pages:
path: /authentication
data:
$ref: ./authentication.md
- title: Pagination
- title: Pagination and Filtering
route:
path: /pagination
path: /pagination-and-filtering
data:
$ref: ./pagination.md
$ref: ./pagination-and-filtering.md
- title: Errors
route:
path: /errors
Expand Down
23 changes: 23 additions & 0 deletions api/openapi/pagination-and-filtering.md
@@ -0,0 +1,23 @@
# Pagination and Filtering

## Pagination

Most endpoints that return a collection are paginated. A paginated response contains metadata about the current page at the root level and the resources in the current page in a child key named after the resource (e.g. `orders`).

You can pass the `page` and `per_page` parameters to set the current page and the desired number of items per page. Note that the default and the maximum number of items per page is decided at the application level.

All pagination metadata is documented in the individual API endpoints, so take a look there if you're unsure what data you can expect.

## Filtering

Most endpoints that return a collection also have the ability to filter data using query params. This works taking advantage of the search filters provided by [Ransack](https://github.com/activerecord-hackery/ransack/).

For example, if we want to retrieve only products that contain the word "Watch" in their title we can make the following request:

```
GET /products?q[name_cont]=Watch
```

The `name_cont` matcher will generate a query using `LIKE` to retrieve all the products that contain the value specified. For an extensive list of search matchers supported, please refer to the Ransack documentation.

The result will be paginated as described in the paragraph above.
7 changes: 0 additions & 7 deletions api/openapi/pagination.md

This file was deleted.

0 comments on commit a139faf

Please sign in to comment.