pub struct EndpointBuilder { /* private fields */ }
Expand description
Builder for Endpoint
.
Implementations§
Source§impl EndpointBuilder
impl EndpointBuilder
Sourcepub fn route<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
pub fn route<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
Absolute route as format template
Variables are written in curly braces {}
.
Examples:
/root/{id}/sub/{arg}
pub fn method<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
pub fn payload_struct<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self
pub fn query_struct<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self
Sourcepub fn result_ok_status<VALUE: Into<String>>(
&mut self,
value: VALUE,
) -> &mut Self
pub fn result_ok_status<VALUE: Into<String>>( &mut self, value: VALUE, ) -> &mut Self
Expected status if query is ok
pub fn result_ko_status<VALUE: Into<Vec<EndpointStatus>>>( &mut self, value: VALUE, ) -> &mut Self
pub fn result_struct<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
Sourcepub fn result_multiple<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
pub fn result_multiple<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
returns a list of results
Sourcepub fn result_is_stream<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
pub fn result_is_stream<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
returns a stream of bytes for this endpoint
This flag generates the --output
arguments.
This flag disables the --format
arguments.
Sourcepub fn extra_header<VALUE: Into<Vec<Header>>>(
&mut self,
value: VALUE,
) -> &mut Self
pub fn extra_header<VALUE: Into<Vec<Header>>>( &mut self, value: VALUE, ) -> &mut Self
Add extra header to this endpoint.
Sourcepub fn extra_action<VALUE: Into<Option<String>>>(
&mut self,
value: VALUE,
) -> &mut Self
pub fn extra_action<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self
Action to run on the data returned by the http call. The signature of the action is: (data:R, settings: &Config)-> Result<()> where R is the struct returned by the api.
Sourcepub fn no_auth<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
pub fn no_auth<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
This endpoint is not authenticated
Sourcepub fn transform_from<VALUE: Into<Option<String>>>(
&mut self,
value: VALUE,
) -> &mut Self
pub fn transform_from<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self
Transform result from this type.
This type should implement TryFrom
for T
and Vec<T>
.
#[derive(Debug, Deserialize)]
struct ApiResult {
status: String,
detail: Option<String>,
result: Option<Vec<MyStruct>>,
}
impl TryFrom<ApiResult> for Vec<MyStruct> {
type Error = String;
fn try_from(value: ApiResult) -> Result<Self, Self::Error> {
// I don't check errors here...
Ok(value.result.clone().unwrap_or_default())
}
}
impl TryFrom<ApiResult> for MyStruct {
type Error = String;
fn try_from(value: ApiResult<MyStruct>) -> Result<Self, Self::Error> {
if value.status == "ERR" {
Err(value.detail.clone().unwrap_or_default())
} else {
let r = value.result.clone().unwrap_or_default();
if r.is_empty() {
Ok(MyStruct::default())
} else {
Ok(r[0].clone())
}
}
}
}
Sourcepub fn cli_route<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
pub fn cli_route<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
clap route separated by slash (/
)
Variables should match the variables declared in the route
configuration.
/command/{id}/subcommand/{arg}
Sourcepub fn cli_help<VALUE: Into<Option<String>>>(
&mut self,
value: VALUE,
) -> &mut Self
pub fn cli_help<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self
Short help string for this endpoint
Sourcepub fn cli_long_help<VALUE: Into<Option<String>>>(
&mut self,
value: VALUE,
) -> &mut Self
pub fn cli_long_help<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self
Long help string for this endpoint.
pub fn cli_visible_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self
pub fn cli_long_flag_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self
pub fn cli_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self
pub fn cli_short_flag_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self
Sourcepub fn cli_no_output<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
pub fn cli_no_output<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self
This empty have no output to display.
It can be combined with the EmptyResponse
result structure.
Examples:
endpoint(
result_ok_status = "NO_CONTENT",
cli_no_output,
result_struct = "EmptyResponse",
route = "...",
cli_route = "...",
),
pub fn cli_output_formats<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self
Sourcepub fn cli_force_output_format<VALUE: Into<bool>>(
&mut self,
value: VALUE,
) -> &mut Self
pub fn cli_force_output_format<VALUE: Into<bool>>( &mut self, value: VALUE, ) -> &mut Self
Force the generation of ‘–format’ args in variable sub command. There’s cases where the arg is not generated automatically.
Example:
/route/{var}'
By default, {var}
don’t generate --format
.
If route is just a passthrough, you need the cli_force_output_format
to generate
the --format
args.
pub fn config<VALUE: Into<Vec<ApiInputConfig>>>( &mut self, value: VALUE, ) -> &mut Self
Trait Implementations§
Source§impl Clone for EndpointBuilder
impl Clone for EndpointBuilder
Source§fn clone(&self) -> EndpointBuilder
fn clone(&self) -> EndpointBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more