Struct EndpointBuilder

Source
pub struct EndpointBuilder { /* private fields */ }
Expand description

Builder for Endpoint.

Implementations§

Source§

impl EndpointBuilder

Source

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}
Source

pub fn method<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self

Source

pub fn payload_struct<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self

Source

pub fn query_struct<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self

Source

pub fn result_ok_status<VALUE: Into<String>>( &mut self, value: VALUE, ) -> &mut Self

Expected status if query is ok

Source

pub fn result_ko_status<VALUE: Into<Vec<EndpointStatus>>>( &mut self, value: VALUE, ) -> &mut Self

Source

pub fn result_struct<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self

Source

pub fn result_multiple<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self

returns a list of results

Source

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.

Source

pub fn extra_header<VALUE: Into<Vec<Header>>>( &mut self, value: VALUE, ) -> &mut Self

Add extra header to this endpoint.

Source

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.

Source

pub fn no_auth<VALUE: Into<bool>>(&mut self, value: VALUE) -> &mut Self

This endpoint is not authenticated

Source

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())
      }
    }
  }
}
Source

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}
Source

pub fn cli_help<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self

Short help string for this endpoint

Source

pub fn cli_long_help<VALUE: Into<Option<String>>>( &mut self, value: VALUE, ) -> &mut Self

Long help string for this endpoint.

Source

pub fn cli_visible_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self

Source

pub fn cli_long_flag_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self

Source

pub fn cli_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self

Source

pub fn cli_short_flag_aliases<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self

Source

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 = "...",
),
Source

pub fn cli_output_formats<VALUE: Into<Option<VecStringWrapper>>>( &mut self, value: VALUE, ) -> &mut Self

Source

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.

Source

pub fn config<VALUE: Into<Vec<ApiInputConfig>>>( &mut self, value: VALUE, ) -> &mut Self

Source

pub fn build(&self) -> Result<Endpoint, EndpointBuilderError>

Builds a new Endpoint.

§Errors

If a required field has not been initialized.

Trait Implementations§

Source§

impl Clone for EndpointBuilder

Source§

fn clone(&self) -> EndpointBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for EndpointBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.