weld icon indicating copy to clipboard operation
weld copied to clipboard

filters, sorting, paging...

Open serayuzgur opened this issue 8 years ago β€’ 2 comments

Field selection

  • Sometimes don’t need all attributes of a resource. Give the API consumer the ability to choose returned fields. This will also reduce the network traffic and speed up the usage of the API.

GET /cars?fields=manufacturer,model,id,color

Paging (Slice)

  • Add _offset and _limit (an X-Total-Count header is included in the response).

GET /cars?_offset=10&_limit=5

  • To send the total entries back to the user use the custom HTTP header: X-Total-Count.

  • Content-Range offset – limit / count.

    • offset: Index of the first element returned by the request.

    • limit: Index of the last element returned by the request.

    • count: Total number of elements in the collection.

  • Accept-Range resource max.

  • resource: The type of pagination. Must remind of the resource in use, e.g: client, order, restaurant, …

  • max : Maximum number of elements that can be returned in a single request.

Sorting

  • Allow ascending and descending sorting over multiple fields.
  • Use sort with underscore as _sort.
  • In code, descending describe as -, ascending describe as +.

GET /cars?_sort=-manufactorer,+model

Operators

  • Add _filter query parameter and continue with field names,operations and values separated by ,.
  • Pattern _filter=<fieldname><operation><value>.
  • Supported operations.
    • = equal
    • != not equal
    • < less
    • <= less or equals
    • > greater
    • >= greater or equals
    • ~= like
    • |= in (values must be separated with |

GET http://127.0.0.1:8080/robe/users?_filter=name=seray,active=true

Full-text search

  • Add _q.

GET /cars?_q=nissan

serayuzgur avatar Apr 18 '17 13:04 serayuzgur

I got error after some queries and application crashed.

Error Detail : Some(Queries { fields: [], filter: [], q: None, paginate: (OFFSET(0), LIMIT(5)), slice: [], sort: [] }) paging LIMIT(5) Some(Queries { fields: [], filter: [], q: None, paginate: (OFFSET(0), LIMIT(5)), slice: [], sort: [] }) thread 'main' panicked at 'called Result::unwrap() on an Err value: ErrorImpl { code: EofWhileParsingValue, line: 1, column: 0 }', src/libcore/result.rs:860 note: Run with RUST_BACKTRACE=1 for a backtrace.

kbukum avatar Aug 16 '17 16:08 kbukum

I checked the issue. It's ok about selection and paging.

Selection Test: http://localhost:8081/posts?_fields=author πŸ‘ http://localhost:8081/posts?_fields=author,tags πŸ‘

Paging Tests:

OK

  • http://localhost:8081/posts?_limit=1 πŸ‘
  • http://localhost:8081/posts?_offset=1 πŸ‘
  • http://localhost:8081/posts?_offset=1&_limit=1 πŸ‘

Selection and Paging Tests

  • http://localhost:8081/posts?_fields=author&_limit=1 πŸ‘
  • http://localhost:8081/posts?_fields=author,tags&_limit=1 πŸ‘
  • http://localhost:8081/posts?_fields=author&_offset=1 πŸ‘
  • http://localhost:8081/posts?_fields=author,tags&_offset=1 πŸ‘

kbukum avatar Aug 16 '17 16:08 kbukum