write less, do more nodejs
nodejs api using jquery simplicity.
jnode uses the file core.js (c14a6b385fa419ce67f115e853fb4a89d8bd8fad) which is at https://github.com/jquery/jquery/blob/master/src/core.js.
jnode aims to be used by an http server. You may also use it without but you might have useless features
What jnode brings :
- an easy configuration of http server
- a static file server
- an api server (with the ability to handle automatic wrapping on result depending on content type expected by the client)
- the $ function of jquery : you can load a module using the $ function or export an handler (discussed below)
- the isFunction, isArray, ... of jquery
- the each, inArray, merge, grep, map, function of jquery
The most explicit is the quit handler bundled with jnode :
$japi'Will be turned off when all the '+serverconnections+' connection(s) will be closed';reqconnectiondestroy;servercloseconsole.log'Exiting';;;
As you can see, the function passed to the $ function expects 3 arguments : the request, the response, and the japi.
japi is a function built-in to jnode used to wrap the result of your handler. In the quit handler, a simple string is retrurned but it also could have been a JSON object. The JSON object would then have been wrapped by the callback if the expected result is jsonp.
You have 2 possibilities to make japi understand which content you expect : query string or HTTP Accept header.
If you want a to have json or jsonp in your response, you have to specify it in the ret query string parameter :
If you have not specified the ret query string parameter, the accept header is used. Which is basically what jquery on client does change.
Here are the allowed content types for json :
Here are the allowed content types for jsonp :