-
-
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 An important design decision here is whether or not we should automatically set the `Content-Type` header. In the issue I wrote that we wouldn't, but during implementation I played around with both options. In the end I went with what was laid out in the issue. The pros and cons of setting it automatically: - Convenient, reduces boilerplate - It may be incorrect, e.g. if the user actually wants `application/geo+json` - Implicit behavior can be confusing - No way to un-set it (you could overwrite the header with an empty value but you can't omit it entirely) - For more complicated types (e.g. forms), we may want to rely on the header to tells us more about the body, which is incompatible with the reverse Another reason to leave it explicit for now is it's a non-breaking change to add the implicit behavior later. Closes #242
- Loading branch information
1 parent
e1eac4c
commit 2a9b2c4
Showing
28 changed files
with
1,457 additions
and
425 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 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,46 @@ | ||
# 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. This may not be necessary though, depending on the server implementation. | ||
|
||
## Supported Content Types | ||
|
||
The following content types have first-class support. All other bodies types must be specified as raw text/binary. | ||
|
||
| Variant | Type | Description | | ||
| ------- | ---- | ---------------------------------------------------------------- | | ||
| `!json` | Any | Structured JSON body, where all strings are treated as templates | | ||
|
||
> Note: Unlike some other HTTP clients, Slumber does **not** automatically set the `Content-Type` header for you. In general you'll want to include that in your request recipe, to tell the server the type of the content you're sending. While this may be inconvenient, it's not possible for Slumber to always know the correct header value, and Slumber's design generally prefers explicitness over convenience. | ||
## 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: Alfonso | ||
|
||
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}}" | ||
headers: | ||
Content-Type: application/json | ||
body: !json { "id": "{{fish_id}}", "name": "Alfonso" } | ||
# This is equivalent to: | ||
# body: '{"id": "{{fish_id}}", "name": "Alfonso"}' | ||
``` |
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
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.