You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+87-5Lines changed: 87 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,16 +83,32 @@ The API must use the following status codes:
83
83
84
84
- The body should also contain a `message` key, containing a more detailled description of the error.
85
85
86
-
```json
86
+
```HTTP
87
+
GET /unicorns/4 HTTP/1.1
88
+
89
+
HTTP/1.1 404 Not Found
90
+
Content-Type: application/json
91
+
87
92
{
88
93
"error": "Not Found",
89
-
"message": "Unable to found user with id '4'"
94
+
"message": "Unable to found unicorn with id '4'"
90
95
}
91
96
```
92
97
93
98
- On validation errors (with a 422 Unprocessable Entity status code), the body should contain a `messages` array containing all the validation errors.
94
99
95
-
```json
100
+
```HTTP
101
+
POST /unicorns HTTP/1.1
102
+
103
+
{
104
+
"unicorn": {
105
+
"color": "purple"
106
+
}
107
+
}
108
+
109
+
HTTP/1.1 422 Unprocessable Entity
110
+
Content-Type: application/json
111
+
96
112
{
97
113
"error": "Validation failed",
98
114
"messages": ["name cannot be blank"]
@@ -113,7 +129,24 @@ Host: api.example.com
113
129
{
114
130
"unicorn": {
115
131
"name": "John",
116
-
"color": "purple"
132
+
"color": "purple",
133
+
"country_id": 1
134
+
}
135
+
}
136
+
137
+
HTTP/1.1 201 Created
138
+
Content-Type: application/json
139
+
140
+
{
141
+
"unicorn": {
142
+
"id": 4,
143
+
"name": "John",
144
+
"color": "purple",
145
+
"created_at": "2016-07-25T12:19:33Z",
146
+
"country": {
147
+
"id": 1,
148
+
"name": "France"
149
+
}
117
150
}
118
151
}
119
152
```
@@ -135,7 +168,7 @@ The API must be versioned, and must not have breaking changes whitout version ch
135
168
- The version field should be formated using the [semantic versioning](http://semver.org/).
136
169
137
170
```HTTP
138
-
GET / HTTP/1.1
171
+
GET /unicorns HTTP/1.1
139
172
Accept: application/vnd.example-app.v3.1+json
140
173
Content-Type: application/json
141
174
Host: api.example.org
@@ -159,13 +192,61 @@ X-Version: 3.1
159
192
160
193
### Sorting
161
194
195
+
The client should be able to
162
196
163
197
### Searching
164
198
165
199
166
200
### Embedding
167
201
168
202
203
+
### Selecting
204
+
205
+
The client should be able to select only specific fields in the response using the `fields` parameter. In this case, only the requested fields will be returned.
206
+
207
+
The value of the `fields` parameter must be a hash of the resource name as a key, and a comma-separated list of the fields names to be returned as a value.
208
+
209
+
```HTTP
210
+
GET /unicorns?fields[unicorns]=id,color&fields[countries]=name HTTP/1.1
211
+
Content-Type: application/json
212
+
Host: api.example.org
213
+
214
+
HTTP/1.1 200 OK
215
+
Content-Type: application/json
216
+
217
+
[
218
+
{
219
+
"id": 1,
220
+
"color": "yellow",
221
+
"country": {
222
+
"name": "Australia"
223
+
}
224
+
},
225
+
{
226
+
"id": 2,
227
+
"color": "green",
228
+
"country": {
229
+
"name": "Italy"
230
+
}
231
+
},
232
+
{
233
+
"id": 3,
234
+
"color": "red",
235
+
"country": {
236
+
"name": "U.S.A"
237
+
}
238
+
},
239
+
{
240
+
"id": 4,
241
+
"color": "purple",
242
+
"country": {
243
+
"name": "France"
244
+
}
245
+
}
246
+
]
247
+
```
248
+
249
+
169
250
### Counting
170
251
171
252
@@ -181,3 +262,4 @@ X-Version: 3.1
181
262
-[Principles of good RESTful API Design](https://codeplanet.io/principles-good-restful-api-design/)
182
263
-[Best Practices for Designing a Pragmatic RESTful API](http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#useful-post-responses)
0 commit comments