Trait pact_consumer::builders::HttpPartBuilder

source ·
pub trait HttpPartBuilder {
    // Provided methods
    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 { ... }
    fn body_matching<P: Into<StringPattern>>(&mut self, body: P) -> &mut Self { ... }
    fn body_matching2<P: Into<StringPattern>, B: Into<String>>(
        &mut self,
        body: P,
        content_type: B,
    ) -> &mut Self { ... }
}
Expand description

Various methods shared between RequestBuilder and ResponseBuilder.

Provided Methods§

source

fn header<N, V>(&mut self, name: N, value: V) -> &mut Self
where N: Into<String>, V: Into<StringPattern>,

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"));
source

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"));
source

fn content_type<CT>(&mut self, content_type: CT) -> &mut Self
where CT: Into<StringPattern>,

Set the Content-Type header.

source

fn html(&mut self) -> &mut Self

Set the Content-Type header to text/html.

source

fn json_utf8(&mut self) -> &mut Self

Set the Content-Type header to application/json; charset=utf-8, with enough flexibility to cover common variations.

source

fn body<B: Into<String>>(&mut self, body: B) -> &mut Self

Specify a body literal. This does not allow using patterns.

use pact_consumer::prelude::*;
use pact_consumer::builders::RequestBuilder;

RequestBuilder::default().body("Hello");
source

fn body2<B: Into<String>>(&mut self, body: B, content_type: B) -> &mut Self

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");
source

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"),
}));
source

fn body_matching<P: Into<StringPattern>>(&mut self, body: P) -> &mut Self

Specify a text body (text/plain) matching the given pattern.

use pact_consumer::prelude::*;
use pact_consumer::builders::RequestBuilder;
use pact_consumer::term;

RequestBuilder::default().body_matching(term!("^(True|False)$", "True"));
source

fn body_matching2<P: Into<StringPattern>, B: Into<String>>( &mut self, body: P, content_type: B, ) -> &mut Self

Specify a text body matching the given pattern with a content type.

use pact_consumer::prelude::*;
use pact_consumer::builders::RequestBuilder;
use pact_consumer::term;

RequestBuilder::default().body_matching2(term!("^(True|False)$", "True"), "text/ascii");

Object Safety§

This trait is not object safe.

Implementors§