Skip to content

Commit

Permalink
Rename recipe to request in collection
Browse files Browse the repository at this point in the history
Also improve UI for folders a bit
  • Loading branch information
LucasPickering committed Apr 17, 2024
1 parent 2b47eb4 commit d049df0
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 79 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

### Breaking

- Rename top-level collection field `requests` to `recipes`
- All existing recipes must be tagged with `!recipe` in the collection file
- All existing recipes must be tagged with `!request` in the collection file
- This is necessary to differentiate from the new `!folder` type
- Profile values are always treated as templates now
- Any profile values that were previously the "raw" variant (the default) that contain template syntax (e.g. `{{user_id}}`) will now be rendered as templates. In reality this is very unlikely, so this probably isn't going to break your setup
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Slumber is based around **collections**. A collection is a group of request **re

```yaml
# slumber.yml
recipes:
get: !recipe
requests:
get: !request
method: GET
url: https://httpbin.org/get
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/request_collection/chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To use a chain in a template, reference it as `{{chains.<id>}}`.
| `selector` | [`JSONPath`](https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html) | Selector to transform/narrow down results in a chained value. See [Filtering & Querying](../../user_guide/filter_query.md) | `null` |
| `content_type` | [`ContentType`](./content_type.md) | Force content type. Not required for `request` and `file` chains, as long as the `Content-Type` header/file extension matches the data | |

See the [`ChainSource`](./chain_source.md) docs for more detail.
See the [`ChainSource`](./chain_source.md) docs for detail on the different types of chainable values.

## Examples

Expand Down
10 changes: 5 additions & 5 deletions docs/src/api/request_collection/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ base: &base
Accept: application/json
Content-Type: application/json

recipes:
login: !recipe
requests:
login: !request
<<: *base
method: POST
url: "{{host}}/anything/login"
Expand All @@ -90,15 +90,15 @@ recipes:
# Folders can be used to keep your recipes organized
users: !folder
children:
get_user: !recipe
requests:
get_user: !request
<<: *base
name: Get User
method: GET
url: "{{host}}/anything/current-user"
authentication: !bearer "{{chains.auth_token}}"

update_user: !recipe
update_user: !request
<<: *base
name: Update User
method: PUT
Expand Down
10 changes: 5 additions & 5 deletions docs/src/api/request_collection/request_recipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Recipes can be organized into folders. This means your set of recipes can form a

## Recipe Fields

The tag for a recipe is `!recipe` (see examples).
The tag for a recipe is `!request` (see examples).

| Field | Type | Description | Default |
| ---------------- | -------------------------------------------- | --------------------------------- | ---------------------- |
Expand All @@ -32,7 +32,7 @@ The tag for a folder is `!folder` (see examples).
## Examples

```yaml
login: !recipe
login: !request
name: Login
method: POST
url: "{{host}}/anything/login"
Expand All @@ -49,14 +49,14 @@ login: !recipe
---
fish: !folder
name: Users
children:
create_fish: !recipe
requests:
create_fish: !request
method: POST
url: "{{host}}/fishes"
body: >
{"kind": "barracuda", "name": "Jimmy"}
list_fish: !recipe
list_fish: !request
method: GET
url: "{{host}}/fishes"
query:
Expand Down
12 changes: 6 additions & 6 deletions docs/src/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Once you've [installed Slumber](/artifacts), setup is easy.
Create a file called `slumber.yml` and add the following contents:

```yaml
recipes:
get: !recipe
requests:
get: !request
method: GET
url: https://httpbin.org/get
```
> Note: the `!recipe` tag, which tells Slumber that this is a request recipe, not a folder. This is [YAML's tag syntax](https://yaml.org/spec/1.2.2/#24-tags), which is used commonly throughout Slumber to provide explicit configuration.
> Note: the `!request` tag, which tells Slumber that this is a request recipe, not a folder. This is [YAML's tag syntax](https://yaml.org/spec/1.2.2/#24-tags), which is used commonly throughout Slumber to provide explicit configuration.

### 2. Run Slumber

Expand All @@ -37,14 +37,14 @@ profiles:
data:
host: https://myfishes.fish
recipes:
create_fish: !recipe
requests:
create_fish: !request
method: POST
url: "{{host}}/fishes"
body: >
{"kind": "barracuda", "name": "Jimmy"}
list_fish: !recipe
list_fish: !request
method: GET
url: "{{host}}/fishes"
query:
Expand Down
6 changes: 3 additions & 3 deletions docs/src/user_guide/chaining_requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ base: &base
Accept: application/json
Content-Type: application/json

recipes:
login: !recipe
requests:
login: !request
<<: *base
method: POST
url: "https://myfishes.fish/login"
Expand All @@ -25,7 +25,7 @@ recipes:
"password": "password"
}
get_user: !recipe
get_user: !request
<<: *base
method: GET
url: "https://myfishes.fish/current-user"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/user_guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ profiles:
data:
host: https://myfishes.fish

recipes:
list_fish: !recipe
requests:
list_fish: !request
method: GET
url: "{{host}}/fishes"
query:
Expand Down
6 changes: 3 additions & 3 deletions docs/src/user_guide/filter_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ base: &base
Accept: application/json
Content-Type: application/json

recipes:
login: !recipe
requests:
login: !request
<<: *base
method: POST
url: "https://myfishes.fish/anything/login"
Expand All @@ -56,7 +56,7 @@ recipes:
"password": "{{chains.password}}"
}
get_user: !recipe
get_user: !request
<<: *base
method: GET
url: "https://myfishes.fish/anything/current-user"
Expand Down
20 changes: 10 additions & 10 deletions docs/src/user_guide/inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ chains:
source: !file
path: ./api_token.txt

recipes:
list_fish: !recipe
requests:
list_fish: !request
method: GET
url: "{{host}}/fishes"
query:
Expand All @@ -26,7 +26,7 @@ recipes:
Accept: application/json
authentication: !bearer "{{chains.token}}"

get_fish: !recipe
get_fish: !request
method: GET
url: "{{host}}/fishes/{{fish_id}}"
headers:
Expand Down Expand Up @@ -57,15 +57,15 @@ request_base: &request_base
Accept: application/json
authentication: !bearer "{{chains.token}}"

recipes:
list_fish: !recipe
requests:
list_fish: !request
<<: *request_base
method: GET
url: "{{host}}/fishes"
query:
big: "true"

get_fish: !recipe
get_fish: !request
<<: *request_base
method: GET
url: "{{host}}/fishes/{{chains.fish_id}}"
Expand Down Expand Up @@ -94,20 +94,20 @@ request_base: &request_base
Accept: application/json
authentication: !bearer "{{chains.token}}"
recipes:
list_fish: !recipe
requests:
list_fish: !request
<<: *request_base
method: GET
url: "{{host}}/fishes"
query:
big: "true"
get_fish: !recipe
get_fish: !request
<<: *request_base
method: GET
url: "{{host}}/fishes/{{chains.fish_id}}"
create_fish: !recipe
create_fish: !request
<<: *request_base
method: POST
url: "{{host}}/fishes"
Expand Down
16 changes: 8 additions & 8 deletions docs/src/user_guide/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ profiles:
data:
host: https://myfishes.fish

recipes:
list_fish: !recipe
requests:
list_fish: !request
method: GET
url: "{{host}}/fishes"
query:
Expand Down Expand Up @@ -65,14 +65,14 @@ chains:
# https://jsonpath.com/
selector: $.id
recipes:
create_fish: !recipe
requests:
create_fish: !request
method: POST
url: "{{host}}/fishes"
body: >
{"kind": "barracuda", "name": "Jimmy"}
get_fish: !recipe
get_fish: !request
method: GET
url: "{{host}}/fishes/{{chains.fish_id}}"
```
Expand Down Expand Up @@ -107,14 +107,14 @@ chains:
recipe: create_fish
selector: $.id
recipes:
create_fish: !recipe
requests:
create_fish: !request
method: POST
url: "{{host}}/fishes"
body: >
{"kind": "barracuda", "name": "Jimmy"}
get_fish: !recipe
get_fish: !request
method: GET
url: "{{host}}/fishes/{{fish_id}}"
```
Expand Down
16 changes: 8 additions & 8 deletions slumber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ base: &base
Accept: application/json
Content-Type: application/json

recipes:
login: !recipe
requests:
login: !request
method: POST
url: "{{host}}/anything/login"
query:
Expand All @@ -53,22 +53,22 @@ recipes:
users: !folder
name: Users
children:
get_users: !recipe
requests:
get_users: !request
<<: *base
name: Get Users
method: GET
url: "{{host}}/get"
query:
foo: bar

get_user: !recipe
get_user: !request
<<: *base
name: Get User
method: GET
url: "{{host}}/anything/{{user_guid}}"

modify_user: !recipe
modify_user: !request
<<: *base
name: Modify User
method: PUT
Expand All @@ -78,14 +78,14 @@ recipes:
"username": "new username"
}
get_image: !recipe
get_image: !request
headers:
Accept: image/png
name: Get Image
method: GET
url: "{{host}}/image"

delay: !recipe
delay: !request
<<: *base
name: Delay
method: GET
Expand Down
12 changes: 9 additions & 3 deletions src/collection/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub struct Collection {
pub profiles: IndexMap<ProfileId, Profile>,
#[serde(default, deserialize_with = "cereal::deserialize_id_map")]
pub chains: IndexMap<ChainId, Chain>,
#[serde(default)]
/// Internally we call these recipes, but to a user `requests` is more
/// intuitive
#[serde(default, rename = "requests")]
pub recipes: RecipeTree,
}

Expand Down Expand Up @@ -59,8 +61,12 @@ pub struct Folder {
#[serde(skip)] // This will be auto-populated from the map key
pub id: RecipeId,
pub name: Option<String>,
/// RECURSION
#[serde(default, deserialize_with = "cereal::deserialize_id_map")]
/// RECURSION. Use `requests` in serde to match the root field.
#[serde(
default,
deserialize_with = "cereal::deserialize_id_map",
rename = "requests"
)]
pub children: IndexMap<RecipeId, RecipeNode>,
}

Expand Down
Loading

0 comments on commit d049df0

Please sign in to comment.