Skip to content

Commit b9c704f

Browse files
committed
Adding selecting
1 parent 0fcd660 commit b9c704f

File tree

1 file changed

+87
-5
lines changed

1 file changed

+87
-5
lines changed

README.md

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,32 @@ The API must use the following status codes:
8383

8484
- The body should also contain a `message` key, containing a more detailled description of the error.
8585

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+
8792
{
8893
"error": "Not Found",
89-
"message": "Unable to found user with id '4'"
94+
"message": "Unable to found unicorn with id '4'"
9095
}
9196
```
9297

9398
- On validation errors (with a 422 Unprocessable Entity status code), the body should contain a `messages` array containing all the validation errors.
9499

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+
96112
{
97113
"error": "Validation failed",
98114
"messages": ["name cannot be blank"]
@@ -113,7 +129,24 @@ Host: api.example.com
113129
{
114130
"unicorn": {
115131
"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+
}
117150
}
118151
}
119152
```
@@ -135,7 +168,7 @@ The API must be versioned, and must not have breaking changes whitout version ch
135168
- The version field should be formated using the [semantic versioning](http://semver.org/).
136169

137170
```HTTP
138-
GET / HTTP/1.1
171+
GET /unicorns HTTP/1.1
139172
Accept: application/vnd.example-app.v3.1+json
140173
Content-Type: application/json
141174
Host: api.example.org
@@ -159,13 +192,61 @@ X-Version: 3.1
159192

160193
### Sorting
161194

195+
The client should be able to
162196

163197
### Searching
164198

165199

166200
### Embedding
167201

168202

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+
169250
### Counting
170251

171252

@@ -181,3 +262,4 @@ X-Version: 3.1
181262
- [Principles of good RESTful API Design](https://codeplanet.io/principles-good-restful-api-design/)
182263
- [Best Practices for Designing a Pragmatic RESTful API](http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#useful-post-responses)
183264
- [Semver](http://semver.org/)
265+
- [JSON API specification](http://jsonapi.org/)

0 commit comments

Comments
 (0)