Show HN: Generate HTTP and Jsonrpc from IDL

(github.com)

2 points | by battery8318 5 hours ago ago

1 comments

  • battery8318 5 hours ago

    I've extended the functionality of (OMG DDS)IDL and written a code generator. It can generate C/C++/Rust/Rust HTTP/Rust JsonRPC/OpenAPI/OpenRPC code from IDL.

    Of course, the Rust HTTP/Rust JsonRPC/OpenAPI/OpenRPC generation is currently more mature.

    I previously used utoipa to generate OpenAPI from code, but I quickly grew tired of the endless boilerplate code. So I made this!!!

    Simply put, you use IDL to describe an HTTP service, and I'll generate an interface, a Service. If you implement an interface for a given interface, I can generate routes for you. It works like this...

    ```rust

    use xidlc_examples::hello_world::HelloWorld;

    use xidlc_examples::hello_world::HelloWorldSayHelloRequest;

    use xidlc_examples::hello_world::HelloWorldServer;

    struct HelloWorldImpl;

    #[async_trait::async_trait]

    impl HelloWorld for HelloWorldImpl {

        async fn sayHello(
    
            &self,
    
            req: 
    xidl_rust_axum::Request<HelloWorldSayHelloRequest>,

        ) -> Result<(), xidl_rust_axum::Error> {
    
            let HelloWorldSayHelloRequest { name } = req.data;
    
            println!("Hello, {}!", name);
    
            Ok(())
        }
    
    }

    #[tokio::main]

    async fn main() -> Result<(), Box<dyn std::error::Error>> {

        let addr = "127.0.0.1:3000";
    
        println!("axum hello_world server listening on {addr}");
    
    
        xidl_rust_axum::Server::builder()
            .with_service(HelloWorldServer::new(HelloWorldImpl))
            .serve(addr)
            .await?;
    
        Ok(())
    } ```

    Currently, support for streaming (HTTP/JsonRPC) is still quite basic. It's defined at https://github.com/xidl/xidl/tree/master/docs/rfc

    Besides that, I've used HTTP/OpenAPI in my project, and I think it currently meets my overall needs.

    Furthermore, xidlc provides simple interfaces for extension. I find xidlc's design truly fascinating.

    I've added some snapshot tests to avoid regression issues.

    I used Google Translate to translate this post, so I'm not sure if it conforms to English grammar. I sincerely hope to receive any feedback, thank you.