Skip to content

Commit 0c86bc0

Browse files
RaschidJFRTomWFox
authored andcommitted
Add keys and excludeKeys options to REST docs (#649)
* Add `keys` and `excludeKeys` options to REST docs * Add `.exclude()` example to JS Guide Added example of Query.exclude() in `js/queries.md` Closes #632 * Moved `keys` and `excludeKeys` from objects.md to queries.md Also: * Added `excludKeys` to the parameter table * Added padding to <td> elements in `_normalize.scss` * Fix typo
1 parent 131698d commit 0c86bc0

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

_includes/js/queries.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ You can skip the first results by setting `skip`. In the old Parse hosted backen
5757
query.skip(10); // skip the first 10 results
5858
```
5959

60-
If you want to know the total number of rows in a table satisfying your query, for e.g. pagination purposes - you can use `withCount`.
60+
If you want to know the total number of rows in a table satisfying your query, for e.g. pagination purposes - you can use `withCount`.
6161

6262
**Note:** Enabling this flag will change the structure of response, see the example below.
6363

@@ -176,6 +176,18 @@ query.find().then(function(results) {
176176
});
177177
```
178178

179+
Similarly, use `exclude` to remove undesired fields while retrieving the rest:
180+
181+
```javascript
182+
var GameScore = Parse.Object.extend("GameScore");
183+
var query = new Parse.Query(GameScore);
184+
query.exclude("playerName");
185+
query.find().then(function(results) {
186+
// Now each result will have all fields except `playerName`
187+
});
188+
```
189+
190+
179191
The remaining fields can be fetched later by calling `fetch` on the returned objects:
180192

181193
```javascript

_includes/rest/objects.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ The response body is a JSON object containing all the user-provided fields, plus
140140
}
141141
```
142142

143-
When retrieving objects that have pointers to children, you can fetch child objects by using the `include` option. For instance, to fetch the object pointed to by the "game" key:
143+
When retrieving objects that have pointers to children, **you can fetch child objects** by using the `include` option. For instance, to fetch the object pointed to by the "game" key:
144144

145145
<div class="language-toggle">
146146
<pre><code class="bash">
@@ -192,6 +192,8 @@ print result
192192
</code></pre>
193193
</div>
194194

195+
196+
195197
## Updating Objects
196198

197199
To change the data on an object that already exists, send a PUT request to the object URL. Any keys you don't specify will remain unchanged, so you can update just a subset of the object's data. For example, if we wanted to change the score field of our object:

_includes/rest/queries.md

+35-9
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,14 @@ print result
302302

303303
In addition to `where`, there are several parameters you can use to configure what types of results are returned by the query.
304304

305-
| Parameter | Use |
306-
|-----------------------------------------------------------------|
307-
| order | Specify a field to sort by |
308-
| limit | Limit the number of objects returned by the query |
309-
| skip | Use with limit to paginate through results |
310-
| keys | Restrict the fields returned by the query |
311-
| include | Use on Pointer columns to return the full object |
305+
| Parameter | Use |
306+
|-------------------------------------------------------------------|
307+
| order | Specify a field to sort by |
308+
| limit | Limit the number of objects returned by the query |
309+
| skip | Use with limit to paginate through results |
310+
| keys | Restrict the fields returned by the query |
311+
| excludeKeys | Exclude specific fields from the returned query |
312+
| include | Use on Pointer columns to return the full object |
312313

313314
You can use the `order` parameter to specify a field to sort by. Prefixing with a negative sign reverses the order. Thus, to retrieve scores in ascending order:
314315

@@ -411,7 +412,7 @@ print result
411412
</code></pre>
412413
</div>
413414

414-
You can restrict the fields returned by passing `keys` a comma-separated list. To retrieve documents that contain only the `score` and `playerName` fields (and also special built-in fields such as `objectId`, `createdAt`, and `updatedAt`):
415+
You can restrict the fields returned by passing `keys` or `excludeKeys` a comma-separated list. To retrieve documents that contain only the `score` and `playerName` fields (and also special built-in fields such as `objectId`, `createdAt`, and `updatedAt`):
415416

416417
<div class="language-toggle">
417418
<pre><code class="bash">
@@ -436,6 +437,31 @@ print result
436437
</code></pre>
437438
</div>
438439

440+
Or you may use `excludeKeys` to fetch everything except `playerName`:
441+
442+
<div class="language-toggle">
443+
<pre><code class="bash">
444+
curl -X GET \
445+
-H "X-Parse-Application-Id: <span class="custom-parse-server-appid">${APPLICATION_ID}</span>" \
446+
-H "X-Parse-REST-API-Key: <span class="custom-parse-server-restapikey">${REST_API_KEY}</span>" \
447+
-G \
448+
--data-urlencode 'excludeKeys=playerName' \
449+
<span class="custom-parse-server-protocol">https</span>://<span class="custom-parse-server-url">YOUR.PARSE-SERVER.HERE</span><span class="custom-parse-server-mount">/parse/</span>classes/GameScore/Ed1nuqPvcm
450+
</code></pre>
451+
<pre><code class="python">
452+
import json,httplib,urllib
453+
connection = httplib.HTTPSConnection('<span class="custom-parse-server-url">YOUR.PARSE-SERVER.HERE</span>', 443)
454+
params = urllib.urlencode({"excludeKeys":"playerName"})
455+
connection.connect()
456+
connection.request('GET', '<span class="custom-parse-server-mount">/parse/</span>classes/GameScore/Ed1nuqPvcm?%s' % params, '', {
457+
"X-Parse-Application-Id": "<span class="custom-parse-server-appid">${APPLICATION_ID}</span>",
458+
"X-Parse-REST-API-Key": "<span class="custom-parse-server-restapikey">${REST_API_KEY}</span>"
459+
})
460+
result = json.loads(connection.getresponse().read())
461+
print result
462+
</code></pre>
463+
</div>
464+
439465
All of these parameters can be used in combination with each other. For example:
440466

441467
<div class="language-toggle">
@@ -1204,4 +1230,4 @@ connection.request('GET', '<span class="custom-parse-server-mount">/parse/</span
12041230
result = json.loads(connection.getresponse().read())
12051231
print result
12061232
</code></pre>
1207-
</div>
1233+
</div>

css/lib/multisite/_normalize.scss

+10-5
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ button,
273273
input,
274274
select,
275275
textarea {
276-
font-size: 100%;
277-
margin: 0;
278-
vertical-align: baseline;
279-
*vertical-align: middle;
276+
font-size: 100%;
277+
margin: 0;
278+
vertical-align: baseline;
279+
*vertical-align: middle;
280280
}
281281

282282
button,
@@ -295,7 +295,7 @@ input[type="reset"],
295295
input[type="submit"] {
296296
-webkit-appearance: button;
297297
cursor: pointer;
298-
*overflow: visible;
298+
*overflow: visible;
299299
}
300300

301301
button[disabled],
@@ -342,3 +342,8 @@ table {
342342
border-collapse: collapse;
343343
border-spacing: 0;
344344
}
345+
346+
td {
347+
padding-left: 12px;
348+
padding-right: 12px;
349+
}

0 commit comments

Comments
 (0)