registerMethod method

void registerMethod (
  1. String name,
  2. Function callback

Registers a method named name on this server.

callback can take either zero or one arguments. If it takes zero, any requests for that method that include parameters will be rejected. If it takes one, it will be passed a Parameters object.

callback can return either a JSON-serializable object or a Future that completes to a JSON-serializable object. Any errors in callback will be reported to the client as JSON-RPC 2.0 errors.


void registerMethod(String name, Function callback) {
  if (_methods.containsKey(name)) {
    throw ArgumentError('There\'s already a method named "$name".');

  _methods[name] = callback;