Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
add README detail
Browse files Browse the repository at this point in the history
  • Loading branch information
jed committed Apr 19, 2012
1 parent f2ab969 commit a89c32b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -39,16 +39,16 @@ server.listen(3000)
How it works
------------

Sajak returns a simple http listener. Upon every request, it:

- parses incoming query, body, and auth data into JavaScript objects,
- instantiates a new model based on the request pathname and query,
- resolves any model URLs in the request into actual model instances,
- calls the user's `authenticate` method to authenticate the user,
- calls the resource's `authorize` method to authorize the user action,
- extends the resource with any incoming body data,
- calls `fetch`/`save`/`destroy` on the resource as per the request method, and
- serializes and returns the results to the client.
Sajak returns a simple http listener. Upon every request, it runs through the following lifecycle:

1. parse the incoming query, body, and auth data into JavaScript objects.
2. instantiate a new model based on the request pathname and query. so `/users/sajak` would call the `User` constructor with `{id: "sajak"}`.
3. instantiate any model URLs in the request. so if you `POST` something like `{"user.href": "/users/sajak", "text": "Hello."}` to `/notes`, the user is reified into an actual `User` instance before being passed to the `Note` constructor.
4. call the `User`'s `authenticate` method to authenticate the user.
5. call the resource's `authorize` method to authorize the user action.
6. extend the resource with any incoming body data.
7. call the appropriate Backbone.js-style `fetch`/`save`/`destroy` method on the resource, as per the request method.
8. serialize and return the results to the client.

Since a Sajak app is just a listener, it can be used standalone, or as middleware in any Express/Connect app. With Express, any requests that don't match or return an error are passed to `next`, as with any other middleware.

Expand Down

0 comments on commit a89c32b

Please sign in to comment.