pub struct Endpoint {Show 24 fields
pub route: String,
pub method: String,
pub payload_struct: Option<String>,
pub query_struct: Option<String>,
pub result_ok_status: String,
pub result_ko_status: Vec<EndpointStatus>,
pub result_struct: String,
pub result_multiple: bool,
pub result_is_stream: bool,
pub extra_header: Vec<Header>,
pub extra_action: Option<String>,
pub no_auth: bool,
pub transform_from: Option<String>,
pub cli_route: String,
pub cli_help: Option<String>,
pub cli_long_help: Option<String>,
pub cli_visible_aliases: Option<VecStringWrapper>,
pub cli_long_flag_aliases: Option<VecStringWrapper>,
pub cli_aliases: Option<VecStringWrapper>,
pub cli_short_flag_aliases: Option<VecStringWrapper>,
pub cli_no_output: bool,
pub cli_output_formats: Option<VecStringWrapper>,
pub cli_force_output_format: bool,
pub config: Vec<ApiInputConfig>,
}
Expand description
Specify an Http endpoint
Fields§
§route: String
Absolute route as format template
Variables are written in curly braces {}
.
Examples:
/root/{id}/sub/{arg}
method: String
§payload_struct: Option<String>
§query_struct: Option<String>
§result_ok_status: String
Expected status if query is ok
result_ko_status: Vec<EndpointStatus>
§result_struct: String
§result_multiple: bool
returns a list of results
result_is_stream: bool
returns a stream of bytes for this endpoint
This flag generates the --output
arguments.
This flag disables the --format
arguments.
extra_header: Vec<Header>
Add extra header to this endpoint.
extra_action: Option<String>
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.
no_auth: bool
This endpoint is not authenticated
transform_from: Option<String>
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())
}
}
}
}
cli_route: String
clap route separated by slash (/
)
Variables should match the variables declared in the route
configuration.
/command/{id}/subcommand/{arg}
cli_help: Option<String>
Short help string for this endpoint
cli_long_help: Option<String>
Long help string for this endpoint.
cli_visible_aliases: Option<VecStringWrapper>
§cli_long_flag_aliases: Option<VecStringWrapper>
§cli_aliases: Option<VecStringWrapper>
§cli_short_flag_aliases: Option<VecStringWrapper>
§cli_no_output: bool
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 = "...",
),
cli_output_formats: Option<VecStringWrapper>
§cli_force_output_format: bool
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.
config: Vec<ApiInputConfig>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Endpoint
impl<'de> Deserialize<'de> for Endpoint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl FromMeta for Endpoint
impl FromMeta for Endpoint
Source§fn from_list(__items: &[NestedMeta]) -> Result<Self>
fn from_list(__items: &[NestedMeta]) -> Result<Self>
fn from_nested_meta(item: &NestedMeta) -> Result<Self, Error>
Source§fn from_meta(item: &Meta) -> Result<Self, Error>
fn from_meta(item: &Meta) -> Result<Self, Error>
syn::Meta
by dispatching to the format-appropriate
trait function. This generally should not be overridden by implementers. Read moreSource§fn from_none() -> Option<Self>
fn from_none() -> Option<Self>
from_none
is used to attempt
recovery before a missing field error is generated. Read moreSource§fn from_word() -> Result<Self, Error>
fn from_word() -> Result<Self, Error>
Source§fn from_value(value: &Lit) -> Result<Self, Error>
fn from_value(value: &Lit) -> Result<Self, Error>
foo = "bar"
or foo("bar")
.
This dispatches to the appropriate method based on the type of literal encountered,
and generally should not be overridden by implementers. Read more