# How to GET with a provided Range?

**URL:** <https://discuss.jsonapi.org/t/how-to-get-with-a-provided-range/412>\
**Category:** Uncategorized\
**Created:** [March 30, 2016, 10:45pm UTC](https://discuss.jsonapi.org/t/how-to-get-with-a-provided-range/412 "2016-03-30T22:45:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewhenderson](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/andrewhenderson/32/115_2.png) [@andrewhenderson](https://discuss.jsonapi.org/u/andrewhenderson)\
**Post date:** [March 30, 2016, 10:45pm UTC](https://discuss.jsonapi.org/t/how-to-get-with-a-provided-range/412/1 "2016-03-30T22:45:35Z")

</div>

I have not found any discussion regarding filtering across a range. For instance, what if you need to `GET` a list of resources between a start and end date?

I propose the following:

```auto
?range[startDate,endDate]=2015-05-01,2015-06-01
```

Any feedback would be appreciated.

---

<div class="post-metadata">

**Author:** ![danielebr](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@danielebr](https://discuss.jsonapi.org/u/danielebr)\
**Post date:** [March 31, 2016, 7:58pm UTC](https://discuss.jsonapi.org/t/how-to-get-with-a-provided-range/412/2 "2016-03-31T19:58:14Z")

</div>

I solved this condition using filters in this way:

- ?filter[pricing\_min]=100
- ?filter[pricing\_max]=200
- ?filter[pricing\_min]=100&filter[pricing\_max]=200

In this way filters and values are parsed following the standard

---

<div class="post-metadata">

**Author:** ![andrewhenderson](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/andrewhenderson/32/115_2.png) [@andrewhenderson](https://discuss.jsonapi.org/u/andrewhenderson)\
**Post date:** [April 1, 2016, 5:41pm UTC](https://discuss.jsonapi.org/t/how-to-get-with-a-provided-range/412/3 "2016-04-01T17:41:54Z")

</div>

I appreciate the feedback.

That is a good use of filters. I think I’ll take your approach.

Worth noting, if I apply your example to my use case, I end up with:  
`
?filter[startDate_min]=2015-05-01&filter[endDate_max]=2015-06-01
`

With our API, I enforce the standard that the key needs to be one that is present on the resource attributes. The only issue one could raise with you approach is that the assumption becomes the resource attribute precedes the underscore `[startDate_min]`.

Basically, the following is the equivalent to an opening range.  
`
_min]=
`

Overall, I like it.

---

<div class="post-metadata">

**Author:** ![danielebr](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@danielebr](https://discuss.jsonapi.org/u/danielebr)\
**Post date:** [April 2, 2016, 8:55am UTC](https://discuss.jsonapi.org/t/how-to-get-with-a-provided-range/412/4 "2016-04-02T08:55:20Z")

</div>

Glad to help 🙂

I wanted to follow your same condition:

> key needs to be one that is present on the resource attributes

but I though that was easier to break this condition in favour of a more linear approach to filters.

This because I implemented a parameters-applier module which applies a query given the attribute. By default it’s a where() clause with equality operator to the attribute but, if specified by an input schema, the default query for the given attribute is replaced with the custom one.  
In this way I just had to write a where() clause with less-than/greater-then operator for the xyz\_min/xyz\_max attributes and the condition is automatically applied to the main query.
