What is CAM?

What is Combo API Methodology or CAM?

This is an idea or methodology I started to think about and developed to solve a problem I came across when developing a website that made a lot of API calls. I also did some searching online to make sure nothing like this existed before taking claim of it, no point in reinventing the wheel. Now, if there is something like this, please feel free to let me know about it. So let's get into it.


Introductory

The Problem

I've developed many community sites and web applications in the past, and when doing so, I would end up making several calls for one page. Lets take a random user profile page for example. On this user profile we need:

  • Profile information
  • Friends of the user
  • User's post or comments

Some calls may even depend on others to retrieve the information. You could approach this one or two ways:

  • Make three separate calls - Problem: Making one call for each method
  • On the back end, make a unique method that combines all three other methods - Problem: Making one unique method that can only be used on a specific page

One may argue that there is nothing wrong with those options, or may point out better solutions that are available. However, my focus is more so on the evolution of API development and how we use it.

The Concept

When I started thinking about this, I combined a few ideas from existing functionalities and methodologies.

First, the functionality. This is from my recent use of React + Redux. Redux allows you to have what is called a "store" which contains a state tree of data. The only way to update the data is by dispatching an action which usually goes through a switch statement and matches the action type to a string to know what action to take when updating the data. Think of it as a highway with exits. Someone or GPS tells you what exit to get off of, and you take that action to accomplish your goal of arriving where you want to go. The highway acts like a pipe of data, everything goes through here.

Second, the methodology. As a front-end developer I've used the BEM methodology for CSS, which stands for Blocks, Elements and Modifiers. You can read more about it here, but basically it's a form of constructing classes where it's readability can tell the developer on how it should be used. This works because of the principles set forth that must be followed for it to work correctly. Which is what we need when creating a methodology.

With these ideas in mind I started contemplating how to combine the best of both worlds to create a great API. I took note that most or all websites had a few things in common, you either are getting or updating data, the data is usually unique to the site, and mostly all API calls are done on the front-end. Processing this information, my overall concept came from thinking of Legos (not surprising), in that you can combine as many different elements in millions of combinations. For this to be possible, each Lego element must follow specific structure, thus allowing them to work with each other.

So lets move on to the URL, where the fun begins.