jaguar_rpc 1.3.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 49

jaguar_rpc

A simple JSON based RPC protocol

Example

HTTP

main() async {
  int contactIdGen = 0;

  // RPC endpoint
  final endpoint = new RpcEndpoint()
    ..route('/get/version', (_) => response(body: {'major': '1', 'minor': '0'}))
    ..route('/add/todo', (RpcRequest req) {
      final newContact = new Contact.fromJson(req.body);
      newContact.id = contactIdGen++;
      contacts.contacts.add(newContact);
      return response(body: contacts.json);
    });

  // Serve the endpoint with Jaguar http server
  final server = new Jaguar();
  server.addApi(rpcOnHttp(endpoint));
  await server.serve();
}

Client:

main() async {
  final client =
      new JsonClient(new http.IOClient(), basePath: 'http://localhost:8080/');
  {
    final resp =
        await client.post('/get/version', body: request('/get/version').toMap);
    final rpcResp = new RpcResponse.decodeJson(resp.bodyStr);
    print(rpcResp.status);
    print(rpcResp.body);
  }
  {
    final resp = await client.post('/add/todo',
        body: request('/add/todo',
                body: new Contact(name: 'teja', email: 'tejainece@gmail.com')
                    .json)
            .toMap);
    final rpcResp = new RpcResponse.decodeJson(resp.bodyStr);
    print(rpcResp.status);
    print(rpcResp.body);
  }
}

Websocket server

main() async {
  int contactIdGen = 0;

  // RPC endpoint
  final endpoint = new RpcEndpoint()
    ..route('/get/version', (_) => response(body: {'major': '1', 'minor': '0'}))
    ..route('/add/todo', (RpcRequest req) {
      final newContact = new Contact.fromJson(req.body);
      newContact.id = contactIdGen++;
      contacts.contacts.add(newContact);
      return response(body: contacts.json);
    });

  // Serve the endpoint with Jaguar http server
  final server = new Jaguar();
  server.get('/ws', rpcOnWebSocket(endpoint));
  await server.serve();
}

Client:

main() async {
  // Client
  final WebSocket socket = await WebSocket.connect('ws://localhost:8080/ws');
  final Stream<RpcResponse> data =
      socket.asBroadcastStream().map((d) => new RpcResponse.decodeJson(d));
  {
    socket.add(request('/get/version').json);
    final RpcResponse rpcResp = await data.first;
    print(rpcResp.status);
    print(rpcResp.body);
  }
  {
    socket.add(request('/add/todo',
            body: new Contact(name: 'teja', email: 'tejainece@gmail.com').toMap)
        .json);
    final RpcResponse rpcResp = await data.first;
    print(rpcResp.status);
    print(rpcResp.body);
  }
}

WebSocket IO client

main() async {
  // Client
  final RpcWebSocketClient socket =
      await RpcWebSocketClient.connect('ws://localhost:8080/ws');
  {
    final RpcResponse rpcResp = await socket.send(request('/get/version'));
    print(rpcResp.status);
    print(rpcResp.body);
  }
  {
    final RpcResponse rpcResp = await socket.send(request('/add/todo',
        body: new Contact(name: 'teja', email: 'tejainece@gmail.com').toMap));
    print(rpcResp.status);
    print(rpcResp.body);
  }
}

Isolate

TODO

TCP

TODO

Plain

main() {
  int contactIdGen = 0;

  final server = new RpcEndpoint()
    ..route('/get/version', (_) => response(body: {'major': '1', 'minor': '0'}))
    ..route('/add/todo', (RpcRequest req) {
      final newContact = new Contact.fromJson(req.body);
      newContact.id = contactIdGen++;
      contacts.contacts.add(newContact);
      return response(body: contacts.json);
    });

  {
    final RpcResponse resp = server.handleRequest(request('/get/unknown'));
    print(resp.status);
  }

  {
    final RpcResponse resp = server.handleRequest(request('/add/todo',
        body: new Contact(name: 'teja', email: 'tejainece@gmail.com').json));
    print(resp.status);
    print(resp.body);
  }
}

Native extension

TODO

TODO

  • [X] HTTP interface
  • [X] Websocket interface
  • [ ] TCP interface
  • [ ] Isolate interface

Changelog

1.0.0

  • RPC request, response and request handler
  • RPC over HTTP
  • RPC over websocket
  • RPC websocket client

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jaguar_rpc: "^1.3.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_rpc/jaguar_rpc.dart';
        
Version Uploaded Documentation Archive
1.3.1 Feb 2, 2018 Go to the documentation of jaguar_rpc 1.3.1 Download jaguar_rpc 1.3.1 archive
1.1.5 Jan 11, 2018 Go to the documentation of jaguar_rpc 1.1.5 Download jaguar_rpc 1.1.5 archive
1.0.0 Dec 23, 2017 Go to the documentation of jaguar_rpc 1.0.0 Download jaguar_rpc 1.0.0 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
98 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
49
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:jaguar_rpc/jaguar_rpc.dart.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 4 hints.

    Strong-mode analysis of lib/src/core/request.dart gave the following hint:

    line: 34 col: 21
    'JSON' is deprecated and shouldn't be used.

    Strong-mode analysis of lib/src/core/response.dart gave the following hint:

    line: 33 col: 21
    'JSON' is deprecated and shouldn't be used.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use jaguar_rpc.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
http ^0.11.1 0.11.3+16
jaguar ^1.3.4 1.3.11
jaguar_client ^0.2.0 0.2.1
Transitive dependencies
args 1.4.2
async 2.0.6
auth_header 0.0.3
charcode 1.1.1
client_cookie 0.1.0 1.0.0
collection 1.14.9
convert 2.0.1
crypto 2.0.2+1
http_parser 3.1.1
http_server 0.9.7
intl 0.15.6
jaguar_common 0.2.2
jaguar_serializer 0.5.1 1.0.0-dev6
logging 0.11.3+1
matcher 0.12.2
meta 1.1.2
mime 0.9.6
path 1.5.1
quiver_iterables 1.0.1
source_span 1.4.0
stack_trace 1.9.2
string_scanner 1.0.2
typed_data 1.1.5
yaml 2.1.13
yamlicious 0.0.5
Dev dependencies
test ^0.12.0