Query strings - ocariot/api-gateway GitHub Wiki

Introduction

Query strings are used as follows: there must be a question mark following the URL and providing the parameters for the desired operations. There are four possible operations: filtering, paging, limiting, and sorting.

Filtering

The attribute name to be used as a parameter and its value must be passed as follows:

attribute_name = attribute_value

Asteristics can be used as follows:

  • *attribute_value - to indicate that you want as any result any item that has this value at the end of the filtered attribute.

  • attribute_value* - to indicate that you want as any result any item that has this value at the beginning of the filtered attribute.

  • Asteristics at the beginning and end to indicate that you want as any result any item that has this value in the middle of the filtered attribute.

  • attribute_value - to indicate that you want as the result the item that has exactly this value in the filtered attribute.

Example:

https://localhost/v1/children?username=*BR*

Pagination

A field named page must be provided with the page to be returned.

Example:

https://localhost/v1/children?page=1

Limitation

A field named limit must be provided with the number of items to be returned.

Example:

https://localhost/v1/children?limit=100

Sorting

A field named sort must be provided containing the names of the attributes, separated by commas, that will be used to sort the result of the query.

For ascending sort, use the '+' character before the attribute name.

For descending sort, use the '-' character before the attribute name.

By default, the order is ascending, so the '+' symbol is optional, just enter the attribute.

Example:

https://localhost/v1/children?sort=username,age

URL example

All parameters can also be used together concatenated by the & character as follows:

https://localhost/v1/children?username=*BR*&sort=username,age&page=1&limit=20