Struct goose::goose::GooseRequestBuilder [−][src]
pub struct GooseRequestBuilder<'a> { /* fields omitted */ }
Expand description
Used to build a GooseRequest
object, necessary to make a request with Goose.
It’s only necessary to build manually if the GooseUser::get
, GooseUser::get_named
,
GooseUser::post
, GooseUser::post_form
, GooseUser::post_json
, GooseUser::head
and GooseUser::delete
helpers don’t provide you with enough flexibility.
Example
use goose::prelude::*;
let mut a_task = task!(task_function);
// A simple task that loads a relative path.
async fn task_function(user: &mut GooseUser) -> GooseTaskResult {
// Manually create a GooseRequestBuilder object.
let goose_request = GooseRequest::builder()
// Set a relative path to request.
.path("about")
// Name the request in the metircs.
.name("About page")
// Build the GooseRequest object.
.build();
// Make the configured request.
let _goose = user.request(goose_request).await?;
Ok(())
}
Implementations
Set the path to request.
Typically is a relative path allowing Goose to append a configurable base_url.
Defaults to ""
(the main index).
Example
This can be implemented in a simpler way using the GooseUser::get
helper function.
use goose::prelude::*;
let mut a_task = task!(task_function);
// A simple task that loads a relative path.
async fn task_function(user: &mut GooseUser) -> GooseTaskResult {
// Manually create a GooseRequestBuilder object.
let goose_request = GooseRequest::builder()
// Set a relative path to request.
.path("a/relative/path")
// Build the GooseRequest object.
.build();
// Make the configured request.
let _goose = user.request(goose_request).await?;
Ok(())
}
Set the method of the request.
Must be set to a GooseMethod
.
Defaults to GooseMethod::Get
.
Example
use goose::prelude::*;
let mut a_task = task!(task_function);
// Make a DELETE request.
async fn task_function(user: &mut GooseUser) -> GooseTaskResult {
// Manually create a GooseRequestBuilder object.
let goose_request = GooseRequest::builder()
// Set a relative path to request.
.path("path/to/delete")
// Set the method to DELETE.
.method(GooseMethod::Delete)
// Build the GooseRequest object.
.build();
// Make the configured DELETE request.
let _goose = user.request(goose_request).await?;
Ok(())
}
Set a name for the request, affecting how it shows up in metrics.
Must be set to a GooseMethod
.
Defaults to GooseMethod::Get
.
Example
use goose::prelude::*;
let mut a_task = task!(task_function);
// Make a named request.
async fn task_function(user: &mut GooseUser) -> GooseTaskResult {
// Manually create a GooseRequestBuilder object.
let goose_request = GooseRequest::builder()
// Set a relative path to request.
.path("path/to/request")
// Name the request in the metrics.
.name("custom name")
// Build the GooseRequest object.
.build();
// Make the configured request.
let _goose = user.request(goose_request).await?;
Ok(())
}
Manually configure the expected HTTP response status code.
Defaults to reqwest::StatusCode::is_success
.
Example
Intentionally request a 404 page, and do not trigger an error.
use goose::prelude::*;
let mut a_task = task!(task_function);
// Make a named request.
async fn task_function(user: &mut GooseUser) -> GooseTaskResult {
// Manually create a GooseRequestBuilder object.
let goose_request = GooseRequest::builder()
// Set a relative path to request.
.path("no/such/path")
// Tell Goose to expect a 404 HTTP response status code.
.expect_status_code(404)
// Build the GooseRequest object.
.build();
// Make the configured request.
let _goose = user.request(goose_request).await?;
Ok(())
}
Manually create the reqwest::RequestBuilder
used to make a request.
Example
Manually create a RequestBuilder
in order to set a timeout.
use goose::prelude::*;
let mut a_task = task!(task_function);
async fn task_function(user: &mut GooseUser) -> GooseTaskResult {
use std::time::Duration;
// Manually interact with the Reqwest RequestBuilder object.
let request_builder = user.get_request_builder(&GooseMethod::Get, "no/such/path")?
// Configure the request to timeout if it takes longer than 500 milliseconds.
.timeout(Duration::from_millis(500));
// Manually build a GooseRequest in order to set our custom RequestBuilder.
let goose_request = GooseRequest::builder()
// Manually add our custom RequestBuilder object.
.set_request_builder(request_builder)
// Turn the GooseRequestBuilder object into a GooseRequest.
.build();
// Finally make the actual request with our custom GooseRequest object.
let _goose = user.request(goose_request).await?;
Ok(())
}
Build the GooseRequest
object which is then passed to GooseUser::request
.
Example
use goose::prelude::*;
// Build the default "GET /".
let goose_request = GooseRequest::builder().build();
Auto Trait Implementations
impl<'a> !RefUnwindSafe for GooseRequestBuilder<'a>
impl<'a> Send for GooseRequestBuilder<'a>
impl<'a> Sync for GooseRequestBuilder<'a>
impl<'a> Unpin for GooseRequestBuilder<'a>
impl<'a> !UnwindSafe for GooseRequestBuilder<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more