[−][src]Macro uni_components_macro::define_service
define_service!() { /* proc-macro */ }
Helps to define new Service
The macros generates new module where all Service-related data will be placed.
There will be:
- In -- type aliase for Service's input type
- Out -- type aliase for Service's output type
(or type itself if
outpus
used instead ofoutput_type
) - Struct -- the structure for which [Service] trait will be implemented
- INSTANCE -- const instance of the Struct
- REF -- 'static ref for Struct (pointing to the INSTANCE)
Parameters
doc
(optional)
String literal which will be used as a documentation for new module. The explanation of the service functionality may be placed here.
name
(required)
Identifier (name) for new module.
input
(required)
Service's input type.
Right now for King::Get services you have to use structure or enum (not String or i32 or etc.)
outputs_type
(one of outputs_type
or outputs
required)
Service's output type. The type have to implement [AsResponse]
and have to have
pub fn from_response(response: uni_components::::Response) -> Result<Self, uni_components::Response>
function.
The best way to implement the type is to use define_type! macro.
Otherwise you can use outputs
parameter and skip outputs_type
.
outputs
(one of outputs_type
or outputs
required)
There you can specify variants how you do for define_type!'s variants
parameter.
You can not have both outputs
and outputs_type
together.
path
(required)
The path where the service will be available at website.
kind
(required)
Select kind of your servce. It should be one of [Kind]s.
Example
define_service!( doc: " Authentication service. It receives user credentials (as a part of authorization request) and then provides token as a response. ", name: AUTH_ACTION, kind: uni_components::Kind::Post, input: common::Auth, outputs: [ AuthorizedToken { code: 200, body: String, doc: "You are authorized to use the service. Token provided" }, NonAuthorized { code: 401, doc: "Non authorized. Probably credentials are incorrect", }, ], path: "/api/login/", );