updated the readme with some details about how the project works
[nodejsws.git] / Readme.md
1 NJSPURLS
2 ========
3
4 Stands for "Node JS, Primary URL Servicer". It is a simple web framework that provides
5 and overhead for createing web applications based on the basic URL. There are manu
6 default parts that are used when servicing a web based applications.
7
8
9 How It Works
10 ============
11
12 In NodeJS you define a layout using NJS script (html with tags that define purls that
13 are called to render pages). For EG if i wanted to create a page "http://host/mypage"
14 then i create a file called ./purls/mypage.js and inside this file i might create the
15 following:
16
17 exports.layout = function(request, response) {
18         var layout = "<html><head><title><?njs title ?></title><body><?njs body ?></body></html>";
19         
20         return layout;
21 }
22
23 exports.title = function(request, response, callback) {
24         response.write("i am a title");
25         callback();
26 }
27
28 exports.body = function(request, response, callback) {
29         response.write("i am a body");
30         callback();
31 }
32
33 A request to http://localhost:8888/mypage will create html that looks like so:
34
35 <html><head><title>i am a title</title></head><body>i am a body</body></html>
36
37 and it does this by printing out the layout then reaplcing the <?njs ... ?> bits 
38 with the functions in the purl defined with the same name of the tag. For EG
39 <?njs body ?> means call the exported function "body" from mypage.js. Defaults
40 also do exist, and so you dont necessarily have to define your own everytime.
41
42
43 Static Files
44 ============
45
46 Static resources are similarly very simple (for eg jpg's, png's, html, etc etc).
47 Any call to njspurls for a url that ends with a file with an extension are assumed
48 to be static... I.e. if the url is http://host/file.ext will make njspurls send a
49 file called "file.ext" from the res directory. URL Paths are not relavent here but
50 any url that ends with a x.y filename at the end WILL be serviced as a static file
51 from the res directory.
52
53 It should be noted that the path to the file in the URL is not important to
54 njspurls, for eg http://host/file.ext is exactly the same as
55 http://host/long/path/file.ext (i.e. the same file will be returned).