apex

Build powerful, versioned APIs with Connect

npm install apex
10 downloads in the last week
25 downloads in the last month

Apex

A Connect-powered toolkit for building APIs.

Inspiration

As a one man development team, it's important to choose the right technology stack. Manpower is extremely limited when compared to a team, and redevelopment often isn't an option. When I set out to build Transistor, I was attracted to Node.js and Connect. Together, they provided a platform suitable for rapid development, developer happiness, and simple testability.

Previously, I was mostly a Ruby developer - and as communities go, Ruby has the best damn developer experience possible. But Node is still growing, and lacks a familiar toolchain.

For instance, my application provided mostly JSON API endpoints, but also rendered a few different HTML templates. This was difficult to construct without two different Connect applications, and during the build, I almost abandoned Node for an evented-Ruby framework. But tools like Formidable convinced me to stay.

So, I spent a day hacking and eventually narrowed my issues with Node to two:

  • Version-restricted REST endpoints (with defaults!)

Apex is a collection of Connect middleware that helps solve the issues above. When pared with Express, you have a powerful, modular web development framework.

Installing

npm install apex

Usage

var express = require('express'),
    apex    = require('apex'),
    app     = express();

app.configure(function () {
  app.use(express.bodyParser());
  // Replaces Express' X-Powered-By header with your own
  app.use(apex.identifier('TestApp'));

  // Configure the API request header to match, and a default version for routes
  apex.versioner.config({ header: 'X-TestApp-Version', default: 1 });
});

// Conditional routes that only respond if the header matches
app.get('/widgets', apex.versioner.limit(2), function (req, res) {
  res.send({ msg: 'Hello from Version 2!' });
});

// Default versioned route
app.get('/widgets', apex.versioner.limit(1), function (req, res) {
    res.send({ msg: 'Hello from Version 1. This is the default' });
});

Contributing

Your contributions are always welcome. If they're useful, I'll merge 'em in. If you consistently submit awesome patches and improvements, I'll probably hand out commit access. That said, I ask you follow a few guidelines:

  • Fork this repository on Github
  • Make your changes, but don't increment the version (I'll handle that.) Please try to comply with existing code formatting practices also.
  • Send a pull request. If I accept several patches, feel free to ask for commit access.

License

Copyright (C) 2012 Nicholas Young/Original Machine LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright holder be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

npm loves you