 to the
given handler method. Regular expressions may also be used, in which case all values captured by
reg-exp capturing groups will be passed as extra parameters to the handler method.

Define more routes to handle updating, reading and deleting Models. The `addRoutes` method is used
below to define routes to handle all actions (create, read, update and delete) for the preceding
Book example:

```javascript
fauxServer.addRoutes({
    createBook: {
        urlExp: "library-app/books",
        httpMethod: "POST",
        handler: function (context) {
            // Create book using attributes in context.data
            // Save to persistence layer
            // Return attributes of newly created book
        }
    },
    readBooks: {
        urlExp: "library-app/books",
        httpMethod: "GET",
        handler: function (context) {
            // Return array of stored book attributes
        }
    },
    readBook: {
        urlExp: "library-app/books/:id",
        httpMethod: "GET",
        handler: function (context, bookId) {
            // Return attributes of stored book with id 'bookId'
        }
    },
    updateBook: {
        urlExp: "library-app/books/:id",
        httpMethod: "PUT",
        handler: function (context, bookId) {
            // Update stored book with id 'bookId', using attributes in context.data
            // Return updated attributes
        }
    },
    deleteBook: {
        urlExp: "library-app/books/:id",
        httpMethod: "DELETE",
        handler: function (context, bookId) {
            // Delete stored book of id 'bookId'
        }
    }
}
```

Route names can be useful for querying and / or removing earlier defined routes. However, this is
often unnecessary and route names may be skipped in most declarations. (They're mandatory as keys
when passing a hash of routes to `addRoutes`.) Coming back to the earlier "createBook" example,
the route name may be skipped like so:

```javascript
fauxServer.addRoute("library-app/books", "POST", function (context) {
    // Create book..
});
```

Moreover, faux-server exposes `get`, `post`, `put`, `del` and `patch` methods as shortcuts for
calling `addRoute` with a specific `httpMethod`. Thus, the preceding POST-route addition may be
rewritten as

```javascript
fauxServer.post("library-app/books", function (context) {
    // Create book..
});
```

Thus, an alternative, more compact syntax for the preceding `addRoutes` example would be:

```javascript
fauxServer
   .post("library-app/books", function (context) {
        // Create book using attributes in context.data
        // Save to persistence layer
        // Return attributes of newly created book

    }).get("library-app/books", function (context) {
        // Return array of stored book attributes

    }).get("library-app/books/:id", function (context, bookId) {
        // Return attributes of stored book with id 'bookId'

    }).put("library-app/books/:id", function (context, bookId) {
        // Update stored book with id 'bookId', using attributes in context.data
        // Return updated attributes

    }).del("library-app/books/:id", function (context, bookId) {
        // Delete stored book of id 'bookId'
    });
}
```


Testing / Contributing
----------------------

The QUnit test suite may be run in a browser (test/index.html) or on the command line, by running
`make test` or `npm test`. The command line version runs on Node and depends on
[node-qunit](https://github.com/kof/node-qunit) (`npm install` to fetch it before testing). A
[coverage report](http://biril.github.io/backbone-faux-server/lcov-report/backbone-faux-server/backbone-faux-server.js.html)
is also available.

Contributions are obviously appreciated. Please commit your changes on the `dev` branch - not
`master`. `dev` is always ahead, contains the latest state of the project and is periodically
merged back to `master` with the appropriate version bump. In lieu of a formal styleguide, take
care to maintain the existing coding style. Please make sure your changes test out green prior to
pull requests.


Reference
---------

The following list, while not exhaustive, includes all essential parts of the BFS API. The omitted
bits are there facilitate fancier stuff you probably won't ever need. Further insight may be gained
by taking a look at
[the examples](https://github.com/biril/backbone-faux-server/tree/master/examples),
[the test suite](https://github.com/biril/backbone-faux-server/tree/master/test) and - of course -
[the source](https://github.com/biril/backbone-faux-server/blob/master/backbone-faux-server.js).
For the latter, an [annotated version](http://biril.github.io/backbone-faux-server/) is also
maintained.

### Methods

All methods return the faux-server instance and may be chained, unless otherwise noted.

#### addRoute ([name, ]urlExp[, httpMethod]&#91;, handler&#93;)

Add a route to the faux-server. Every route defines a mapping from a Model(or Collection)-URL &
sync-method (an HTTP verb (POST, GET, PUT, PATCH or DELETE)) to some specific handler (callback):

`<model-URL, sync-method> → handler`

Whenever a Model is created, read, updated or deleted, its URL and the the sync method being
used are tested against defined routes in order to find a handler for creating, reading,
updating or deleting this Model. The same applies to reading Collections: Whenever a Collection is
read, its URL (and the'read' method) will be tested against defined routes in order to find a
handler for reading it. When a match for the `<model-URL, sync-method>` pair is not found among
defined routes, the native sync is invoked (this behaviour may be overridden - see
`fauxServer.setDefaultHandler`). Later routes take precedence over earlier routes so in
configurations where multiple routes match, the one most recently defined will be used.

* `name`: Name of this route. Optional. A named route may be queried and / or removed by its name
    (see `getRoute` / `removeRoute`) and will replace an earlier defined route of same name.
* `urlExp`: An expression against which, Model(or Collection)-URLs will be tested. This is
    syntactically and functionally analogous to
    [Backbone routes](http://backbonejs.org/#Router-routes): `urlExp`s may contain parameter parts,
    `:param`, which match a single URL component between slashes; and splat parts `*splat`, which
    can match any number of URL components. Parentheses may also be used to denote optional parts.
    The values captured by params and splats will be passed as parameters to the given handler
    method. Regular expressions may also be used, in which case all values captured by
    reg-exp capturing groups will be passed as parameters to the given handler method. Note that
    `:param`s are required to begin with a letter or underscore - those that don't are treated as
    a fixed part of the URL. The expression `http://example.com:8080` contains _no_ `:param` parts.
* `httpMethod`: The sync method, (an HTTP verb (POST, GET, PUT, PATCH or DELETE)), that should
    trigger the route's handler. Both the URL-expression and the method should match for the
    handler to be invoked. `httpMethod` may also be set to '*' or omitted to create a
    match-all-methods handler: One that will be invoked whenever `urlExp` matches the model's (or
    collection's) URL _regardless_ of method. In the scope of a match-all-methods handler, the HTTP
    method currently being handled may be acquired by querying the `context` parameter for
    `context.httpMethod`. Note that when `Backbone.emulateHTTP` is set to true or `emulateHTTP` is
    passed as an inline option during sync, 'create', 'update', 'patch' and 'delete' will all be
    mapped to POST. In this case `context.httpMethod` will be set to POST and the true HTTP method
    being handled may be acquired by querying `context.httpMethod