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: Anywhereobject
required
Dictionary of method functions by name.
Calling Methods
Meteor.call()
Invokes a method with a sync stub, passing any number of arguments. Locus: Anywherestring
required
Name of method to invoke
any
Optional method arguments
function
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: Anywherestring
required
Name of method to invoke
any
Optional method arguments
Promise
Meteor.apply()
Invoke a method passing an array of arguments. Locus: Anywherestring
required
Name of method to invoke
array
required
Method arguments
object
Optional options object
boolean
(Client only) If true, don’t send this method until all previous method calls have completed.
function
(Client only) This callback is invoked with the error or result of the method as soon as the error or result is available.
boolean
(Client only) If true, don’t send this method again on reload, simply call the callback an error with the error code ‘invocation-failed’.
boolean
(Client only) If true, exceptions thrown by method stubs will be thrown instead of logged.
boolean
(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:
string
The id of the user that made this method call, or
null if no user was logged in.object
Access to the connection that called this method.
null for server-initiated methods.boolean
true if this invocation is a stub on the client, false if running on the server.function
(Server only) Set the logged-in user.
function
(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: