Skip to content

Commit e767a8e

Browse files
committed
update minimal example in readme
1 parent 812dec5 commit e767a8e

17 files changed

+301
-35
lines changed

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ A minimal API
6262
id = fields.Integer(as_string=True, dump_only=True)
6363
name = fields.String()
6464
65+
@pre_load
66+
def remove_id_before_deserializing(self, data, **kwargs):
67+
"""
68+
We don't want to allow editing ID on POST / PATCH
69+
70+
Related issues:
71+
https://github.com/AdCombo/flask-combo-jsonapi/issues/34
72+
https://github.com/miLibris/flask-rest-jsonapi/issues/193
73+
"""
74+
if 'id' in data:
75+
del data['id']
76+
return data
6577
6678
# Create resource managers
6779
class PersonList(ResourceList):

docs/http_snippets/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ python3 update_snippets_with_responses.py
6060

6161
> **Pro tip:** run webserver for specs before running update_snippets_with_responses, otherwise it won't work 😉
6262
63+
64+
Copy-paste resulting help text (from between the "===" lines) to make includes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"method": "DELETE",
3+
"url": "http://localhost:5000/persons/1",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
]
13+
}

docs/http_snippets/minimal_api__get_person.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"method": "GET",
3-
"url": "http://localhost:5000/persons",
3+
"url": "http://localhost:5000/persons/1",
44
"httpVersion": "HTTP/1.1",
55
"queryString": [
66
],
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "PATCH",
3+
"url": "http://localhost:5000/persons/1",
4+
"httpVersion": "HTTP/1.1",
5+
"queryString": [
6+
],
7+
"headers": [
8+
{
9+
"name": "content-type",
10+
"value": "application/vnd.api+json"
11+
}
12+
],
13+
"postData": {
14+
"mimeType": "application/json",
15+
"text": "{\n \"data\": {\n \"id\": 1,\n \"type\": \"person\",\n \"attributes\": {\n \"name\": \"Sam\"\n }\n }\n}"
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DELETE /persons/1 HTTP/1.1
2+
Content-Type: application/vnd.api+json
3+
Host: localhost:5000
4+
5+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/vnd.api+json
3+
4+
{
5+
"jsonapi": {
6+
"version": "1.0"
7+
},
8+
"meta": {
9+
"message": "Object successfully deleted"
10+
}
11+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
GET /persons HTTP/1.1
1+
GET /persons/1 HTTP/1.1
22
Content-Type: application/vnd.api+json
33
Host: localhost:5000
4+
5+

docs/http_snippets/snippets/minimal_api__get_person_result

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,20 @@ HTTP/1.1 200 OK
22
Content-Type: application/vnd.api+json
33

44
{
5-
"data": [
6-
{
7-
"attributes": {
8-
"name": "John"
9-
},
10-
"id": "1",
11-
"links": {
12-
"self": "/persons/1"
13-
},
14-
"type": "person"
5+
"data": {
6+
"attributes": {
7+
"name": "John"
158
},
16-
{
17-
"attributes": {
18-
"name": "Sam"
19-
},
20-
"id": "2",
21-
"links": {
22-
"self": "/persons/2"
23-
},
24-
"type": "person"
25-
}
26-
],
9+
"id": "1",
10+
"links": {
11+
"self": "/persons/1"
12+
},
13+
"type": "person"
14+
},
2715
"jsonapi": {
2816
"version": "1.0"
2917
},
3018
"links": {
31-
"first": "http://localhost:5000/persons",
32-
"last": "http://localhost:5000/persons?page%5Bnumber%5D=2",
33-
"next": "http://localhost:5000/persons?page%5Bnumber%5D=2",
34-
"self": "http://localhost:5000/persons"
35-
},
36-
"meta": {
37-
"count": 2
19+
"self": "/persons/1"
3820
}
3921
}

0 commit comments

Comments
 (0)