Adding logic to your component

How to work with component ports

Open up the newly generated component file at ./src/components/ and add to it so it looks like this:

pub use crate::components::generated::greet::*;

impl wasmflow_sdk::v1::ephemeral::BatchedComponent for Component {
    async fn job(
        inputs: Self::Inputs,
        outputs: Self::Outputs,
        _config: Option<Self::Config>,
    ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
        let greeting = format!("Hello {}", inputs.input);

Take note of these lines:

let greeting = format!("Hello {}", inputs.input);

The first line uses Rust’s format!() macro to format our input string into a suitable greeting.

The second line takes that greeting string and pushes it to the output port named output.

Finally, done() sends a packet and closes the port in one command.


Change the port names in your Apex schema and rebuild your component to see how the code generation reflects the changes.

Build and run your component with the new logic to see the output:

$ make
$ wasmflow invoke ./build/my_project.signed.wasm greet -- --input="my_input"
{"output":{"value":"Hello my_input"}}

Change the inputs.input expression to something like inputs.input.to_uppercase() to see how modules can act on data as it comes through.

Next we’ll add new components to our collection.