-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes content parsing a bit more generic, to set us up for more content types. Still needs some work though, not 100% ready.
- Loading branch information
1 parent
e122869
commit 79aa0eb
Showing
12 changed files
with
321 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Content Type | ||
|
||
Content type defines the various data formats that Slumber recognizes and can manipulate. Slumber is capable of displaying any text-based data format, but only specific formats support additional features such as [querying](../user_guide/filter_query.md) and formatting. | ||
|
||
For chained requests, Slumber uses the [HTTP `Content-Type` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) to detect the content type. For chained files, it uses the file extension. For other [chain sources](./chain_source.md), or if the `Content-Type` header/file extension is missing or incorrect, you'll have to manually provide the content type via the [chain](./chain.md) `content_type` field. | ||
|
||
## Supported Content Types | ||
|
||
| Content Type | HTTP Header | File Extension(s) | | ||
| ------------ | ------------------ | ----------------- | | ||
| JSON | `application/json` | `json` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Data Filtering & Querying | ||
|
||
Slumber supports querying data structures to transform or reduce response data. | ||
|
||
There are two main use cases for querying: | ||
|
||
- In [chained template values](../api/chain.md), to extract data | ||
- Provided via chain's `selector` argument | ||
- In the TUI response body browser, to limit the response data shown | ||
|
||
**Regardless of data format, querying is done via [JSONPath](https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html).** For non-JSON formats, the data will be converted to JSON, queried, and converted back. This keeps querying simple and uniform across data types. | ||
|
||
## Querying Chained Values | ||
|
||
Here's some examples of using queries to extract data from a chained value. Let's say you have two chained value sources. The first is a JSON file, called `creds.json`. It has the following contents: | ||
|
||
```json | ||
{ "user": "fishman", "pw": "hunter2" } | ||
``` | ||
|
||
We'll use these credentials to log in and get an API token, so the second data source is the login response, which looks like so: | ||
|
||
```json | ||
{ "token": "abcdef123" } | ||
``` | ||
|
||
```yaml | ||
chains: | ||
username: | ||
source: !file ./creds.json | ||
selector: $.user | ||
password: | ||
source: !file ./creds.json | ||
selector: $.pw | ||
auth_token: | ||
source: !request login | ||
selector: $.token | ||
|
||
# Use YAML anchors for de-duplication | ||
base: &base | ||
headers: | ||
Accept: application/json | ||
Content-Type: application/json | ||
|
||
requests: | ||
login: | ||
<<: *base | ||
method: POST | ||
url: "https://myfishes.fish/anything/login" | ||
body: | | ||
{ | ||
"username": "{{chains.username}}", | ||
"password": "{{chains.password}}" | ||
} | ||
get_user: | ||
<<: *base | ||
method: GET | ||
url: "https://myfishes.fish/anything/current-user" | ||
query: | ||
auth: "{{chains.auth_token}}" | ||
``` | ||
While this example simple extracts inner fields, JSONPath can be used for much more powerful transformations. See the [JSONPath docs](https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html) for more examples. | ||
<!-- TODO add screenshot of in-TUI querying --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.