Skip to content

Commit

Permalink
Add keys and excludeKeys options to REST docs (#649)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RaschidJFR authored and TomWFox committed Jul 28, 2019
1 parent 131698d commit 0c86bc0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
14 changes: 13 additions & 1 deletion _includes/js/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You can skip the first results by setting `skip`. In the old Parse hosted backen
query.skip(10); // skip the first 10 results
```

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`.
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`.

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

Expand Down Expand Up @@ -176,6 +176,18 @@ query.find().then(function(results) {
});
```

Similarly, use `exclude` to remove undesired fields while retrieving the rest:

```javascript
var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
query.exclude("playerName");
query.find().then(function(results) {
// Now each result will have all fields except `playerName`
});
```


The remaining fields can be fetched later by calling `fetch` on the returned objects:

```javascript
Expand Down
4 changes: 3 additions & 1 deletion _includes/rest/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ The response body is a JSON object containing all the user-provided fields, plus
}
```

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:
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:

<div class="language-toggle">
<pre><code class="bash">
Expand Down Expand Up @@ -192,6 +192,8 @@ print result
</code></pre>
</div>



## Updating Objects

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:
Expand Down
44 changes: 35 additions & 9 deletions _includes/rest/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,14 @@ print result

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

| Parameter | Use |
|-----------------------------------------------------------------|
| order | Specify a field to sort by |
| limit | Limit the number of objects returned by the query |
| skip | Use with limit to paginate through results |
| keys | Restrict the fields returned by the query |
| include | Use on Pointer columns to return the full object |
| Parameter | Use |
|-------------------------------------------------------------------|
| order | Specify a field to sort by |
| limit | Limit the number of objects returned by the query |
| skip | Use with limit to paginate through results |
| keys | Restrict the fields returned by the query |
| excludeKeys | Exclude specific fields from the returned query |
| include | Use on Pointer columns to return the full object |

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:

Expand Down Expand Up @@ -411,7 +412,7 @@ print result
</code></pre>
</div>

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`):
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`):

<div class="language-toggle">
<pre><code class="bash">
Expand All @@ -436,6 +437,31 @@ print result
</code></pre>
</div>

Or you may use `excludeKeys` to fetch everything except `playerName`:

<div class="language-toggle">
<pre><code class="bash">
curl -X GET \
-H "X-Parse-Application-Id: <span class="custom-parse-server-appid">${APPLICATION_ID}</span>" \
-H "X-Parse-REST-API-Key: <span class="custom-parse-server-restapikey">${REST_API_KEY}</span>" \
-G \
--data-urlencode 'excludeKeys=playerName' \
<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
</code></pre>
<pre><code class="python">
import json,httplib,urllib
connection = httplib.HTTPSConnection('<span class="custom-parse-server-url">YOUR.PARSE-SERVER.HERE</span>', 443)
params = urllib.urlencode({"excludeKeys":"playerName"})
connection.connect()
connection.request('GET', '<span class="custom-parse-server-mount">/parse/</span>classes/GameScore/Ed1nuqPvcm?%s' % params, '', {
"X-Parse-Application-Id": "<span class="custom-parse-server-appid">${APPLICATION_ID}</span>",
"X-Parse-REST-API-Key": "<span class="custom-parse-server-restapikey">${REST_API_KEY}</span>"
})
result = json.loads(connection.getresponse().read())
print result
</code></pre>
</div>

All of these parameters can be used in combination with each other. For example:

<div class="language-toggle">
Expand Down Expand Up @@ -1204,4 +1230,4 @@ connection.request('GET', '<span class="custom-parse-server-mount">/parse/</span
result = json.loads(connection.getresponse().read())
print result
</code></pre>
</div>
</div>
15 changes: 10 additions & 5 deletions css/lib/multisite/_normalize.scss
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ button,
input,
select,
textarea {
font-size: 100%;
margin: 0;
vertical-align: baseline;
*vertical-align: middle;
font-size: 100%;
margin: 0;
vertical-align: baseline;
*vertical-align: middle;
}

button,
Expand All @@ -295,7 +295,7 @@ input[type="reset"],
input[type="submit"] {
-webkit-appearance: button;
cursor: pointer;
*overflow: visible;
*overflow: visible;
}

button[disabled],
Expand Down Expand Up @@ -342,3 +342,8 @@ table {
border-collapse: collapse;
border-spacing: 0;
}

td {
padding-left: 12px;
padding-right: 12px;
}

0 comments on commit 0c86bc0

Please sign in to comment.