Giter Site home page Giter Site logo

Comments (6)

KaiserKarel avatar KaiserKarel commented on June 2, 2024 1

Probably a trait with the datatypes, and perhaps a a feature flag to only import the API definition without the actual server implementation (that's how I do it when using gRPC). Both the server and the client can depend on a single shared trait.

Server crate

pub trait API {
    fn get() -> Foo;
}

#[cfg(feature=server)]
mod server {
    pub struct Server {} 

    impl API for Server ...
}

Pallet crate

use server::API;

struct Client;

impl API for Client { 
    # pallet offchain worker logic here.
} 

from composable.

KaiserKarel avatar KaiserKarel commented on June 2, 2024

I'd move the interface definition to the server implementation, and import that into the offchain worker. Where is the price-feed server defined?

from composable.

hussein-aitlahcen avatar hussein-aitlahcen commented on June 2, 2024

When you say importing that to the offchain worker. Do you mean importing the whole project as a dependency? The only "interface" we currently have is the http endpoint along with the JSON schema expected by the offchain worker (just wrapping the price), here in the server

from composable.

hussein-aitlahcen avatar hussein-aitlahcen commented on June 2, 2024

Ok that makes sense :)!

from composable.

KaiserKarel avatar KaiserKarel commented on June 2, 2024

At least, I really like this pattern :) Since the server is kind of in charge of the API spec, it is logical to define the interface there as well. But now you do get a well defined API. It also allows for easy embedding in over different protocols.

tower plays really nicely with different frameworks and protocols too. If only we had async traits already, it'd be perfect.

from composable.

hussein-aitlahcen avatar hussein-aitlahcen commented on June 2, 2024

Of course this pattern is nice :).
It reminds me of Servant in Haskell, were we share the API so that you end up being able to automatically derive the client.

from composable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.