@@ -15,7 +15,7 @@ pip install rest-api-response
15
15
2). In the file (.py) that you wish to use it, import it:
16
16
17
17
``` python
18
- from rest_api_response import success_response, error_response
18
+ from rest_api_response import success_response, error_response
19
19
```
20
20
21
21
That's pretty much it - you can now call the function and pass the required arguments!
@@ -41,23 +41,23 @@ class PostListAPIView(views.APIView):
41
41
The API response would be:
42
42
43
43
``` json
44
- [
45
- {
46
- "title" : " First blog post" ,
47
- "content" : " Lorem ipsume content" ,
48
- "author" : 1
49
- },
50
- {
51
- "title" : " Second blog post" ,
52
- "content" : " Lorem ipsume content" ,
53
- "author" : 2
54
- },
55
- {
56
- "title" : " Third blog post" ,
57
- "content" : " Lorem ipsume content" ,
58
- "author" : 3
59
- }
60
- ]
44
+ [
45
+ {
46
+ "title" : " First blog post" ,
47
+ "content" : " Lorem ipsume content" ,
48
+ "author" : 1
49
+ },
50
+ {
51
+ "title" : " Second blog post" ,
52
+ "content" : " Lorem ipsume content" ,
53
+ "author" : 2
54
+ },
55
+ {
56
+ "title" : " Third blog post" ,
57
+ "content" : " Lorem ipsume content" ,
58
+ "author" : 3
59
+ }
60
+ ]
61
61
```
62
62
63
63
This works too, but let's take the response to the next level by doing this:
@@ -86,26 +86,27 @@ class PostListAPIView(views.APIView):
86
86
The API response would be:
87
87
88
88
``` json
89
- [ "status" : true ,
90
- "message " : " Posts retrieved! " ,
91
- "data " : [
92
- {
93
- "title" : " First blog post " ,
94
- "content " : " Lorem ipsume content " ,
95
- "author" : 1
96
- },
97
- {
98
- "title" : " Second blog post " ,
99
- "content " : " Lorem ipsume content " ,
100
- "author" : 2
101
- },
102
- {
103
- "title" : " Third blog post " ,
104
- "content " : " Lorem ipsume content " ,
105
- "author" : 3
106
- }
107
- ]
89
+ [
90
+ "status " : true ,
91
+ "message " : " Posts retrieved! " ,
92
+ "data" : [
93
+ {
94
+ "title " : " First blog post " ,
95
+ "content" : " Lorem ipsume content " ,
96
+ "author" : 1
97
+ },
98
+ {
99
+ "title " : " Second blog post " ,
100
+ "content" : " Lorem ipsume content " ,
101
+ "author" : 2
102
+ },
103
+ {
104
+ "title " : " Third blog post " ,
105
+ "content" : " Lorem ipsume content " ,
106
+ "author" : 3
107
+ }
108
108
]
109
+ ]
109
110
```
110
111
111
112
And that's it. You have a nicely catchy response. :-)
0 commit comments