Methods API
Methods are Meteor’s remote procedure call (RPC) system, used to save data to the server and get return values. Source:packages/ddp-client/, packages/ddp-server/
Defining Methods
Meteor.methods()
Defines functions that can be invoked over the network by clients. Locus: AnywhereDictionary of method functions by name.
Calling Methods
Meteor.call()
Invokes a method with a sync stub, passing any number of arguments. Locus: AnywhereName of method to invoke
Optional method arguments
Optional callback, which is called asynchronously with the error or result after the method is complete.
Meteor.callAsync()
Invokes a method with an async stub, passing any number of arguments. Returns a Promise. Locus: AnywhereName of method to invoke
Optional method arguments
Promise
Meteor.apply()
Invoke a method passing an array of arguments. Locus: AnywhereName of method to invoke
Method arguments
Optional options object
(Client only) If true, don’t send this method until all previous method calls have completed.
(Client only) This callback is invoked with the error or result of the method as soon as the error or result is available.
(Client only) If true, don’t send this method again on reload, simply call the callback an error with the error code ‘invocation-failed’.
(Client only) If true, exceptions thrown by method stubs will be thrown instead of logged.
(Client only) If true, return the stub’s return value instead of undefined.
Meteor.applyAsync()
Invoke a method passing an array of arguments, returning a Promise. Locus: AnywhereMethod Context (this)
Inside a method function,this is bound to a method invocation object with the following properties:
The id of the user that made this method call, or
null if no user was logged in.Access to the connection that called this method.
null for server-initiated methods.true if this invocation is a stub on the client, false if running on the server.(Server only) Set the logged-in user.
(Server only) Call this function to allow other methods from the same client to run while this method is still executing.
Method Simulation (Latency Compensation)
Methods defined on both client and server run on the client first (simulation/stub), then on the server.Error Handling
Throwing Errors
Catching Errors
Validation
Always validate method arguments using thecheck package: