Some qualities of good API design:
- Modular.
- Reusable.
- Easy to use.
- Difficult to misuse.
- Powerful to do what it needs to do.
- Easy to expand.
iHale
iHale top-level architecture |
But where do we begin?
The Scope
For this particular system there are few design requirements that we must fulfill. Our system has to interact with sensors for all of the house devices. We decided to model the system by having a main system which manages different environments that contain different devices. In our current Restlet API design, we tried to create resource objects to be sent across HTTP to issue commands to "actuators" (i.e. - turn lights on and off) and to be able to accept data from "sensors".
Generalizing the problem
Because we don't know exactly what type of hardware we are working with, we created a highly abstract API for our initial design. We felt that actuators and sensors are pretty similar, so we have them both extend a parent class called Device. The idea behind this design choice is to allow for these different resources to have their own unique ID numbers that is generated using a static variable that increments itself every time a device is created. This provides a simple way to reference a specific device that will not be confused with another.
Though we don't know exactly what sensors the device will be talking to, we know that we will be using REST to send data between the iHale system and the devices. Therefore we have to have a way to send GET and PUT request methods at the least. How we handle the requests at the moment, we're unsure. The main thing is that we let the users with the parameters they need to provide and what they can expect in return.
"Through Fire and Flames"
Our group met a few times over a week and spent a few good hours drawing up different designs, shooting down the bad ideas and keeping the good ones. But even after all the time that was spent on our design, in its current state I feel like we're going to have to end up redoing it. Why?
We were so focused on creating everything from the ground up, generalizing and abstracting that I think we got a little carried away. What we forgot to do is to look at the existing APIs for the systems we are using. Namely, Restlet's API which already provides the Resource class. Instead of creating a class that already sort of exists! Apart from saving us the time of coding an entirely new class, it would allow for even more compatibility with Restlet and its pre-existing methods!
Thoughts
Even though I think our first API design was perfect, it was a great experience in software design. It pushed us to step back and view every part of the system, and even future expansions of the project. While it is good to be able to think abstractly about the system, you want to keep yourself grounded and work within your scopes (in our case the services we are using). Fortunately for us the API is in the early stages of development, so its good for us to catch our mistakes now instead of later.
You can check out Team Maka's latest API distribution here.