registerMethod method

void registerMethod (String name, 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.

Implementation

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

  _methods[name] = callback;
}