Support file-esque chain in request body
Did you search for existing issues already? Yes
Is your feature request related to a problem? Please describe. I wanted to open this more as a discussion, I am aware we can do:
chains:
big_file:
source: !file
path: Cargo.lock
big_file: !request
name: Big File
method: POST
url: "{{host}}/anything"
body: "{{chains.big_file}}"
But I'm wondering if it would make sense for the following to be supported when you have large collections in order to keep the configuration concise:
big_file: !request
name: Big File
method: POST
url: "{{host}}/anything"
body: !file Cargo.lock
For my use case, I would end up having to create a chain for every single request as our organisation has JSON requests for testing checked in to version control as json files, and parsing these into my slumber.yaml does not seem like a good direction to go.
Describe the solution you'd like Add a new body type variant for enabling simpler configuration to a json file
Describe alternatives you've considered Chains
Additional context This might just want to allow json, could also be bundled into the existing json! variant, but I imagine this would add unnecessary complexity.
@LucasPickering Let me know what you think, happy to continue work on the draft linked above if you think this is something that would be useful across the board :)
I totally agree, one of my gripes with the chain system is that it's very verbose, and there's no way to define chains inline. I've spent the past few months working on completely replacing the collection config system to eliminate YAML in favor of something that would make it easier to reuse recipe components, as well as make inline stuff like this easier. I've gone through a lot of variations of this, but right now I'm working on doing it in a simple JavaScript subset. In that world, your recipe would look something like:
big_file: {
name: "Big File",
method: "POST",
url: ({ host }) => `${host}/anything`
body: () => file('Cargo.lock')
}
What do you think of this? Do you think it would make your collections easier to write and maintain?
Unfortunately the downside of this is it's still a few months away at least. I'm going to leave this issue open since it's an active problem, but I don't really want to apply any short term fixes because it will take away from time working on the new system. So for now I think the answer is you'll have to keep using the verbose chains :(
Oh wow a big rewrite. I've just been playing around with https://yamlscript.org/. Could this be a better solution than needing to maintain something more custom? Could be used as a preprocess and also allow arbitrary execution of functions to replace chains?
I can see the benefits to having something simpler of course and like the above example you've given, I just have concern over the maintenance burden it might lead to for you!
I'm surprised I didn't find YAMLscript in my many hours of research, but after looking at it I think the syntax is really opaque and hard to follow. My goal is to use something approachable and obvious, which is why I landed on JS, since it's so ubiquitous. It is a large upfront cost but I think in the long term it will make the tool more maintainable.
Yeh I will admit that even getting it up and running and pre-processing the yaml in the way I wanted caused me some grief. Also adds a dependency to using slumber outside of cargo with the .so
You also raise a good point, there doesn't seem to be a simple config language that supports functions out the box, was surprised! Closest I could find was https://pkl-lang.org/index.html
Update on this: I've been working on an overhaul of the template language. Config is going to remain in YAML, but templates will support functions, eliminating the need for chains. So my example from above will instead look like:
big_file:
type: request
name: "Big File",
method: "POST",
url: "{{ host }}/anything"
body: "{{ file('Cargo.lock') }}"
The implementation for this is mostly working but I'm still ironing out some final parts before I can release a public beta. I'll let you know when it's available though.
The new template function syntax just released in 4.0 makes this much easier: https://slumber.lucaspickering.me/api/template_functions.html#file
You can now do:
requests:
big_file:
name: Big File
method: POST
url: "{{host}}/anything"
body: "{{ file('Cargo.lock') }}"
and if you want to use it in multiple places you can still pull it out into the profile:
.profile_data:
big_file: "{{ file('Cargo.lock') }}"
profiles:
prd:
data:
$ref: "#/.profile_data"
requests:
big_file1:
name: Big File
method: POST
url: "{{host}}/anything"
body: "{{ big_file }}"
big_file2:
name: Big File
method: POST
url: "{{host}}/anything"
body: "{{ big_file }}"