{"_id":"56207bb1bc7b320d007ddb05","version":{"_id":"56000f0e8c0c9d0d00dcad24","project":"56000f0d8c0c9d0d00dcad21","__v":13,"createdAt":"2015-09-21T14:07:10.176Z","releaseDate":"2015-09-21T14:07:10.176Z","categories":["56000f0e8c0c9d0d00dcad25","56008f2497f69f1700f21a36","560091601503430d007cc936","560e0d8054af2b0d005bbe92","560e3ce7ad6b200d00ff471c","560e3cf2c4e4ae0d00b42ed1","561c81d0e822e12b00e1fe00","561c81e9e822e12b00e1fe01","561c823d20b4a92b007d5147","56257f8951bf1c0d001f660a","562d5f165bd25e0d0054dbd4","562d68d5d38b650d0044472a","56421aebb0dc090d00f88438"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"56000f0d8c0c9d0d00dcad21","user":"5600910981a9670d006d144f","__v":5,"githubsync":"","category":{"_id":"56257f8951bf1c0d001f660a","version":"56000f0e8c0c9d0d00dcad24","__v":5,"pages":["5625965051bf1c0d001f6618","5625965e4dcb400d00ff4467","5625966aaf0b001900361600","5625967151bf1c0d001f661a","5626c430fcbbc621004ebf1e"],"project":"56000f0d8c0c9d0d00dcad21","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-19T23:40:57.283Z","from_sync":false,"order":5,"slug":"spacemessaging","title":"space:messaging"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-16T04:23:13.397Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Purpose\"\n}\n[/block]\nDefine an interface for sending Commands, or to call Meteor.Methods if not using messaging architecture. Each _method_ defined in a `Space.messaging.Api` is a `Meteor.method`, which if named the same as a Command becomes an endpoint the application's CommandBus delivers to. If not a Command, it can be used with `Meteor.call` or `Meteor.apply`as per normal.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Examples\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// On server\\nMy.Api = Space.messaging.Api.extend(My,'Api', {\\n\\n  dependencies: {\\n    things: 'My.ThingsCollection'\\n  }\\n\\n  methods() {\\n    return [{\\n      'My.Command': function (context, command) {\\n        if(context && !context.userId)\\n          throw new this.meteor.Error('You must be logged in to do this')\\n        this.commandBus.send(command)\\n      },\\n      'getThingsTotal': function (context, options) {\\n        if(context && !context.userId)\\n          throw new this.meteor.Error('You must be logged in to do this')\\n        return this.things.find(options).count()\\n      }\\n    }]\\n  }\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nHere you can see an example of both a Command and generic endpoint, with a simple validation example of checking the user is logged in.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Testing\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"myCommand = new MyCommand(…)\\nMy.App.test(My.Api).given().send(myCommand).expect(myCommand)\\nMy.App.test(My.Api).given().call(myCommand).expect(function({ //expectation }))\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"Space.messaging.Api","slug":"api","type":"basic","title":"Api"}

Api

Space.messaging.Api

[block:api-header] { "type": "basic", "title": "Purpose" } [/block] Define an interface for sending Commands, or to call Meteor.Methods if not using messaging architecture. Each _method_ defined in a `Space.messaging.Api` is a `Meteor.method`, which if named the same as a Command becomes an endpoint the application's CommandBus delivers to. If not a Command, it can be used with `Meteor.call` or `Meteor.apply`as per normal. [block:api-header] { "type": "basic", "title": "Examples" } [/block] [block:code] { "codes": [ { "code": "// On server\nMy.Api = Space.messaging.Api.extend(My,'Api', {\n\n dependencies: {\n things: 'My.ThingsCollection'\n }\n\n methods() {\n return [{\n 'My.Command': function (context, command) {\n if(context && !context.userId)\n throw new this.meteor.Error('You must be logged in to do this')\n this.commandBus.send(command)\n },\n 'getThingsTotal': function (context, options) {\n if(context && !context.userId)\n throw new this.meteor.Error('You must be logged in to do this')\n return this.things.find(options).count()\n }\n }]\n }\n});", "language": "javascript" } ] } [/block] Here you can see an example of both a Command and generic endpoint, with a simple validation example of checking the user is logged in. [block:api-header] { "type": "basic", "title": "Testing" } [/block] [block:code] { "codes": [ { "code": "myCommand = new MyCommand(…)\nMy.App.test(My.Api).given().send(myCommand).expect(myCommand)\nMy.App.test(My.Api).given().call(myCommand).expect(function({ //expectation }))", "language": "javascript" } ] } [/block]