Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

mattress

0.2.1 • Public • Published

Mattress Build Status

Mattress is a small framework, a foundation if you will, on top of which you can build APIs – Mattress is not a web framework, it is an API framework. It was and is based on restify and borrows heavily from it, but differs in some aspects. Despite it's name, Mattress will not automatically create REST APIs for you. Whether or not your API is actually RESTful depends on you.

Got ideas and/or feature requests? Please file an issue.

Things Mattress does

a.k.a features!

  • Content negoitation
  • HTTP and HTTPS
  • HTTP Basic Authentication
  • Versioned routes

Quick start

A server that simply echos "Hello world." (available as examples/hello-world.js):

"use strict";
 
var Mattress = require("..");
 
var v1 = {
    "GET":
        function GET(request, response) {
            response.write("Hello world.\n");
            response.end();
        }
};
 
var media = {
    "text/plain": { "1": v1 }
};
 
Mattress
.createServer({
    "routes": [{
        "path": "/hello",
        "media": media
    }]
})
.listen(8888, function () {
    console.log("Server listening on port 8888");
});

Running:

$ curl -i localhost:8888/hello -H "Accept: text/plain; v = 1"

Will output:

HTTP/1.1 200 OK
Content-Type: text/plain; version = 1; charset = utf-8
Date: Tue, 18 Feb 2014 03:07:07 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Hello world.

Running tests

$ grunt test

License

This software is released under the ISC License. See LICENSE.md for more information.

Keywords

none

Install

npm i mattress

DownloadsWeekly Downloads

1

Version

0.2.1

License

ISC

Last publish

Collaborators

  • avatar