pub struct Collection {
pub name: Option<String>,
pub requests: Vec<Request>,
}Expand description
A named group of requests living in one YAML file.
name: Example API # optional, a label for the collection as a whole
requests:
- name: List users # required inside a collection: it is the selector
method: GET
url: https://api.example.com/users
- name: Create user
method: POST
url: https://api.example.com/users
body: '{"name": "ada"}'requests is a list, not a map of name-to-request, for two reasons.
First, each entry is then exactly a single-request file: a request can be
lifted into a collection (or pulled back out into its own file) verbatim,
with its name staying a field instead of becoming a key. There is one
request shape in Sendra, not two. Second, a list preserves file order,
which is the order sendra run <file> sends them in; the map types serde
reaches for either sort the entries (BTreeMap) or need a dependency
(IndexMap) to avoid it. Lookup by name is then a linear scan, which costs
nothing at the sizes a hand-written collection reaches.
Fields§
§name: Option<String>§requests: Vec<Request>Implementations§
Source§impl Collection
impl Collection
Sourcepub fn get(&self, name: &str) -> Result<&Request, SendraError>
pub fn get(&self, name: &str) -> Result<&Request, SendraError>
Look a request up by its name.
Errors with SendraError::RequestNotFound, which carries the names
that do exist, rather than returning a bare Option — a missing name
is a user-facing mistake worth a good message everywhere it happens.
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Source§fn clone(&self) -> Collection
fn clone(&self) -> Collection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more