Trait pact_consumer::prelude::HttpPartBuilder
source · [−]pub trait HttpPartBuilder {
fn header<N, V>(&mut self, name: N, value: V) -> &mut Self
where
N: Into<String>,
V: Into<StringPattern>,
{ ... }
fn header_from_provider_state<N, E, V>(
&mut self,
name: N,
expression: E,
value: V
) -> &mut Self
where
N: Into<String>,
E: Into<String>,
V: Into<StringPattern>,
{ ... }
fn content_type<CT>(&mut self, content_type: CT) -> &mut Self
where
CT: Into<StringPattern>,
{ ... }
fn html(&mut self) -> &mut Self { ... }
fn json_utf8(&mut self) -> &mut Self { ... }
fn body<B: Into<String>>(&mut self, body: B) -> &mut Self { ... }
fn body2<B: Into<String>>(&mut self, body: B, content_type: B) -> &mut Self { ... }
fn json_body<B: Into<JsonPattern>>(&mut self, body: B) -> &mut Self { ... }
}
Expand description
Various methods shared between RequestBuilder
and ResponseBuilder
.
Provided Methods
Specify a header pattern.
use pact_consumer::prelude::*;
use pact_consumer::*;
use pact_consumer::builders::RequestBuilder;
use regex::Regex;
RequestBuilder::default()
.header("X-Simple", "value")
.header("X-Digits", term!("^[0-9]+$", "123"));
fn header_from_provider_state<N, E, V>(
&mut self,
name: N,
expression: E,
value: V
) -> &mut Self where
N: Into<String>,
E: Into<String>,
V: Into<StringPattern>,
fn header_from_provider_state<N, E, V>(
&mut self,
name: N,
expression: E,
value: V
) -> &mut Self where
N: Into<String>,
E: Into<String>,
V: Into<StringPattern>,
Specify a header pattern and a generator from provider state.
use pact_consumer::prelude::*;
use pact_consumer::*;
use pact_consumer::builders::RequestBuilder;
use regex::Regex;
RequestBuilder::default()
.header_from_provider_state("X-Simple", "providerState", "value")
.header_from_provider_state("X-Digits", "providerState", term!("^[0-9]+$", "123"));
fn content_type<CT>(&mut self, content_type: CT) -> &mut Self where
CT: Into<StringPattern>,
fn content_type<CT>(&mut self, content_type: CT) -> &mut Self where
CT: Into<StringPattern>,
Set the Content-Type
header.
Set the Content-Type
header to application/json; charset=utf-8
,
with enough flexibility to cover common variations.
Specify a body literal. This does not allow using patterns.
use pact_consumer::prelude::*;
use pact_consumer::builders::RequestBuilder;
RequestBuilder::default().body("Hello");
TODO: We may want to change this to B: Into<Vec<u8>>
depending on what
happens with https://github.com/pact-foundation/pact-reference/issues/19
Specify a body literal with content type. This does not allow using patterns.
use pact_consumer::prelude::*;
use pact_consumer::builders::RequestBuilder;
RequestBuilder::default().body2("Hello", "plain/text");
TODO: We may want to change this to B: Into<Vec<u8>>
depending on what
happens with https://github.com/pact-foundation/pact-reference/issues/19
fn json_body<B: Into<JsonPattern>>(&mut self, body: B) -> &mut Self
fn json_body<B: Into<JsonPattern>>(&mut self, body: B) -> &mut Self
Specify the body as JsonPattern
, possibly including special matching
rules.
use pact_consumer::prelude::*;
use pact_consumer::*;
use pact_consumer::builders::RequestBuilder;
RequestBuilder::default().json_body(json_pattern!({
"message": like!("Hello"),
}));