-
-
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.
Add !json variant for structured bodies
- Add !json tag to `body` field of recipes - !json bodies can contain any data. Strings will be treated as templates The original design in the ticket was to use have the user still provide `Content-Type`, but I realized there isn't much value in that. It just requires more work for the user, and introduces another thing we need to validate (body type vs `Content-Type`). If the user needs a subset of `application/json` they can still override it. Otherwise, providing it ourselves is just more convenient. The other motivating factor behind is forms. The machinery that reqwest gives us to set form data automatically sets the header, so I think it makes sense to follow that lead. Closes #242
- Loading branch information
1 parent
e1eac4c
commit 5efb7e2
Showing
30 changed files
with
1,555 additions
and
444 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
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,49 @@ | ||
# Recipe Body | ||
|
||
There are a variety of ways to define the body of your request. Slumber supports structured bodies for a fixed set of known content types (see table below). | ||
|
||
In addition, you can pass any [`Template`](./template.md) to render any text or binary data. In this case, you'll probably want to explicitly set the `Content-Type` header to tell the server what kind of data you're sending. This may not be necessary though, depending on the server implementation. | ||
|
||
## Supported Content Types | ||
|
||
The following content types have first-class support. The meaning of each column is as follows: | ||
|
||
- Variant - Tag used when defining a body of this type | ||
- Type - Type of the associated value | ||
- `Content-Type` - Value to insert for the `Content-Type` request header | ||
- Additionally, this is the associated content type when determining how to [parse chained responses for the purposes of filtering/querying](../../user_guide/filter_query.md). | ||
- File Extension - File extension(s) that map to this content type when determining how to [parse chained files for the purposes of filtering/querying](../../user_guide/filter_query.md) | ||
|
||
| Variant | Type | `Content-Type` | File Extension | Description | | ||
| ------- | ---- | ------------------ | -------------- | ---------------------------------------------------------------- | | ||
| `!json` | Any | `application/json` | `json` | Structured JSON body, where all strings are treated as templates | | ||
|
||
## Examples | ||
|
||
```yaml | ||
chains: | ||
image: | ||
source: !file | ||
path: ./fish.png | ||
|
||
requests: | ||
text_body: !request | ||
method: POST | ||
url: "{{host}}/fishes/{{fish_id}}/name" | ||
headers: | ||
Content-Type: text/plain | ||
body: Balthazar | ||
|
||
binary_body: !request | ||
method: POST | ||
url: "{{host}}/fishes/{{fish_id}}/image" | ||
headers: | ||
Content-Type: image/jpg | ||
body: "{{chains.fish_image}}" | ||
|
||
json_body: !request | ||
method: POST | ||
url: "{{host}}/fishes/{{fish_id}}" | ||
# Content-Type header will be set automatically based on the body type | ||
body: !json { "name": "Balthazar" } | ||
``` |
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
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.