Skip to content

agilord/json_rpc_adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP client and shelf server adapters for easier JSON-RPC

Automatic RPC bindings using mirrors

Takes an abstract class API definition with at most one argument on each method:

abstract class TestApi {
  Future<ObjRs> incrementObject(ObjRq rq);
  Future<String> incrementInt(int x);

  Future<void> setter(int x);
  /// Note: `int?` is not supported here yet, only non-null `int`.
  Future<int?> getter();
}

Use reflection to get a shelf handler:

    final api = TestApiImpl();
    final handler = JsonRpcShelfHandler()
      ..registerApi<TestApi>(api);

User reflection to get a http-based client:

class TestApiClient extends ReflectedApiClient<TestApi> implements TestApi {
  TestApiClient(super.client);
}
    final client = JsonRpcHttpClient(
      endpoint: 'http://localhost:8080/',
    );
    final reflectedApi = TestApiClient(client);

See more

See usage in the test directory: https://github.com/agilord/json_rpc_adapter/tree/master/test

About

Dart package for HTTP client and shelf server adapters for easier JSON-RPC (optional mirrors for automatic binding)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages