Organize your Meteor Application with Maka-CLI Generators, Part 1: API

$ maka generate —help
Maka generate
$ maka g:api trucks
trucks!
  • “created … /trucks-collection.jsx” this is a mongo collection definition for Meteor. It contains the Trucks class, and you can override the normal mongo methods or add your special methods.
  • “created … /rpc-methods.jsx” this a Remote Procedure Call (RPC)definition file, and contains all code that will run on the server, but called via the client. It’s a very powerful and dangerous file and should be used with care.
  • “created … /fixtures.jsx” this file contains functions that should run on application startup. For example, inserting a user into the database if there are no users.
  • “created … /publications.jsx” This is a stub file with a simple pair of publishing methods for the new trucks resource.
  • “created app/imports/startup/server/register-trucks-API.jsx” This is an “overhead” file that cobbles together all the rest of the API resources files for import into the application. If you decide to delete the trucks directory, you’ll need to delete this file, and the files it references. Don’t worry; Meteor will remind you.
  • “updated /Users/mjc/blahblahblah/app/imports/startup/server/index.jsx” This file was updated by simply appending an import of “register-trucks-api.jsx” so the trucks resource can be injected into the rest of the server side code. Again, if you delete the trucks resource, you’ll need to delete the one line added to this file.

trucks-collection.jsx

rpc-methods.jsx

fixtures.jsx

publications.jsx

server/index.jsx

Recap!

Phew! Well, that was a lot of stuff. I hope this provides a deeper understanding of what Maka-CLI is doing when you go to generate a new API resource. For more advanced usage on APIs, especially with GraphQL, head on over to my other article on setting up a GraphQL server!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store