Book Image

Build Applications with Meteor

Book Image

Build Applications with Meteor

Overview of this book

This book starts with the basic installation and overview of the main components in Meteor. You’ll get hands-on multiple versatile applications covering a wide range of topics from adding a front-end views with the hottest rendering technology React to implementing a microservices oriented architecture.All the code is written with ES6/7 which is the latest significantly improved JavaScript language. We’ll also look at real-time data streaming, server to server data exchange, responsive styles on the front-end, full-text search functionality, and integration of many third-party libraries and APIs using npm. By the end of the book, you’ll have the skills to quickly prototype and even launch your next app idea in a matter of days.
Table of Contents (16 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
8
Build a Chatbot with Facebook’s Messenger Platform

Meteor methods


To make our app work with methods, we need to create tree methods and move all the edits from the client to the server.

Let's place all the methods in a folder called api on the root of the client. The concept of Methods is very similar to Ajax calls to the server:

On the server, we can define them when on the startup:

  Meteor.startup(() => {
….. Methods definition
});
 Meteor.methods({
cartInsert: function(product) {
      CartCollection.insert({
       'title' : product.title,
       'price' : product.price,
       'inventory' : product.inventory,
       'quantity': 1
 });
 },

In Meteor.methods, we can define all the methods.

Let's start by adding the product method in the cart.

The cartInsert method is the name of the method and, in the body function, we can just copy exactly the same code that we had on the client.

To call that method on the client, we do it with Meteor.call('cartInsert', product);.

On the client, in the api/index.js, we create all the methods and export them...