Skip to content

Commit e51bca8

Browse files
committed
Add complex filtering example
1 parent fc9a549 commit e51bca8

14 files changed

+467
-0
lines changed

docs/api_filtering_example.rst

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Filtering API example
2+
======================
3+
4+
.. literalinclude:: ../examples/api_complex_filtering.py
5+
:language: python
6+
7+
8+
Check existing persons
9+
10+
Request:
11+
12+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons
13+
:language: HTTP
14+
15+
Response:
16+
17+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons_result
18+
:language: HTTP
19+
20+
21+
22+
Filter by word
23+
24+
.. code-block:: json
25+
26+
[
27+
{
28+
"name": "words",
29+
"op": "in",
30+
"val": "spam"
31+
}
32+
]
33+
34+
Request:
35+
36+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons__filter_word_in_array
37+
:language: HTTP
38+
39+
Response:
40+
41+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons__filter_word_in_array_result
42+
:language: HTTP
43+
44+
45+
Filter by words
46+
47+
.. code-block:: json
48+
49+
[
50+
{
51+
"name": "words",
52+
"op": "in",
53+
"val": ["bar", "eggs"]
54+
}
55+
]
56+
57+
Request:
58+
59+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons__filter_words_in_array
60+
:language: HTTP
61+
62+
Response:
63+
64+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons__filter_words_in_array_result
65+
:language: HTTP
66+
67+
68+
Filter by any word containing value
69+
70+
.. code-block:: json
71+
72+
[
73+
{
74+
"name": "words",
75+
"op": "ilike_in_str_array",
76+
"val": "green"
77+
}
78+
]
79+
80+
Request:
81+
82+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons__filter_word_contains_in_array
83+
:language: HTTP
84+
85+
Response:
86+
87+
.. literalinclude:: ./http_snippets/snippets/api_filtering__get_persons__filter_word_contains_in_array_result
88+
:language: HTTP
89+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"method": "GET",
3+
"url": "http://localhost:5000/persons",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
]
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"method": "GET",
3+
"url": "http://localhost:5000/persons?filter=[{\"name\":\"words\",\"op\":\"ilike_in_str_array\",\"val\":\"green\"}]",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
]
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"method": "GET",
3+
"url": "http://localhost:5000/persons?filter=[{\"name\":\"words\",\"op\":\"in\",\"val\":\"spam\"}]",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
]
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"method": "GET",
3+
"url": "http://localhost:5000/persons?filter=[{\"name\":\"words\",\"op\":\"in\",\"val\":[\"bar\",\"eggs\"]}]",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
]
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GET /persons HTTP/1.1
2+
Content-Type: application/vnd.api+json
3+
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GET /persons?filter=%5B%7B%22name%22%3A%22words%22%2C%22op%22%3A%22ilike_in_str_array%22%2C%22val%22%3A%22green%22%7D%5D HTTP/1.1
2+
Content-Type: application/vnd.api+json
3+
4+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/vnd.api+json
3+
4+
{
5+
"data": [
6+
{
7+
"attributes": {
8+
"name": "John",
9+
"words": [
10+
"foo",
11+
"bar",
12+
"green-grass"
13+
]
14+
},
15+
"id": "1",
16+
"links": {
17+
"self": "/persons/1"
18+
},
19+
"type": "person"
20+
},
21+
{
22+
"attributes": {
23+
"name": "Sam",
24+
"words": [
25+
"spam",
26+
"eggs",
27+
"green-apple"
28+
]
29+
},
30+
"id": "2",
31+
"links": {
32+
"self": "/persons/2"
33+
},
34+
"type": "person"
35+
}
36+
],
37+
"jsonapi": {
38+
"version": "1.0"
39+
},
40+
"links": {
41+
"self": "http://localhost:5000/persons?filter=%5B%7B%22name%22%3A%22words%22%2C%22op%22%3A%22ilike_in_str_array%22%2C%22val%22%3A%22green%22%7D%5D"
42+
},
43+
"meta": {
44+
"count": 2
45+
}
46+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GET /persons?filter=%5B%7B%22name%22%3A%22words%22%2C%22op%22%3A%22in%22%2C%22val%22%3A%22spam%22%7D%5D HTTP/1.1
2+
Content-Type: application/vnd.api+json
3+
4+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/vnd.api+json
3+
4+
{
5+
"data": [
6+
{
7+
"attributes": {
8+
"name": "Sam",
9+
"words": [
10+
"spam",
11+
"eggs",
12+
"green-apple"
13+
]
14+
},
15+
"id": "2",
16+
"links": {
17+
"self": "/persons/2"
18+
},
19+
"type": "person"
20+
}
21+
],
22+
"jsonapi": {
23+
"version": "1.0"
24+
},
25+
"links": {
26+
"self": "http://localhost:5000/persons?filter=%5B%7B%22name%22%3A%22words%22%2C%22op%22%3A%22in%22%2C%22val%22%3A%22spam%22%7D%5D"
27+
},
28+
"meta": {
29+
"count": 1
30+
}
31+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GET /persons?filter=%5B%7B%22name%22%3A%22words%22%2C%22op%22%3A%22in%22%2C%22val%22%3A%5B%22bar%22%2C%22eggs%22%5D%7D%5D HTTP/1.1
2+
Content-Type: application/vnd.api+json
3+
4+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/vnd.api+json
3+
4+
{
5+
"data": [
6+
{
7+
"attributes": {
8+
"name": "John",
9+
"words": [
10+
"foo",
11+
"bar",
12+
"green-grass"
13+
]
14+
},
15+
"id": "1",
16+
"links": {
17+
"self": "/persons/1"
18+
},
19+
"type": "person"
20+
},
21+
{
22+
"attributes": {
23+
"name": "Sam",
24+
"words": [
25+
"spam",
26+
"eggs",
27+
"green-apple"
28+
]
29+
},
30+
"id": "2",
31+
"links": {
32+
"self": "/persons/2"
33+
},
34+
"type": "person"
35+
}
36+
],
37+
"jsonapi": {
38+
"version": "1.0"
39+
},
40+
"links": {
41+
"self": "http://localhost:5000/persons?filter=%5B%7B%22name%22%3A%22words%22%2C%22op%22%3A%22in%22%2C%22val%22%3A%5B%22bar%22%2C%22eggs%22%5D%7D%5D"
42+
},
43+
"meta": {
44+
"count": 2
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/vnd.api+json
3+
4+
{
5+
"data": [
6+
{
7+
"attributes": {
8+
"name": "John",
9+
"words": [
10+
"foo",
11+
"bar",
12+
"green-grass"
13+
]
14+
},
15+
"id": "1",
16+
"links": {
17+
"self": "/persons/1"
18+
},
19+
"type": "person"
20+
},
21+
{
22+
"attributes": {
23+
"name": "Sam",
24+
"words": [
25+
"spam",
26+
"eggs",
27+
"green-apple"
28+
]
29+
},
30+
"id": "2",
31+
"links": {
32+
"self": "/persons/2"
33+
},
34+
"type": "person"
35+
}
36+
],
37+
"jsonapi": {
38+
"version": "1.0"
39+
},
40+
"links": {
41+
"self": "http://localhost:5000/persons"
42+
},
43+
"meta": {
44+
"count": 2
45+
}
46+
}

0 commit comments

Comments
 (0)