Permalink
Browse files

changed example, added @JSON

  • Loading branch information...
1 parent 2bf0d4a commit c7a49d431e55842702cc9e877d7183ce8bec8862 @warmuuh committed Apr 5, 2013
View
15 express-example/MyService.js
@@ -9,16 +9,13 @@ MyService.prototype = {
return 'index';
},
- test: function (name, id)/*@POST("/test/:id") @Param*/ {
- return {view:'test', model:{name: name, id: id}};
- },
-
- rest: function( /*@Body*/msg,
- /*@Param*/id,
- /*@Autowired*/test)
- /*@POST("/rest/:id") @Body*/ {
- return {msg: msg, id: id, wired: test};
+ submit: function (name, age)/*@POST @Param*/ {
+ var msg = (age < 18)? "You are too young" : "You are welcome!";
+ return {view:'greet', model:{name: name, msg: msg}};
+
}
+
+
};
View
7 express-example/views/greet.jade
@@ -0,0 +1,7 @@
+html
+ head
+ body
+ h1|Hello, #{name}!
+ p=msg
+
+
View
6 express-example/views/index.jade
@@ -3,7 +3,11 @@ html
body
h1|Hello, what is your name?
div
- form(name="input", action='/test/1',method='post')
+ form(name="input", action='/submit',method='post')
label(for='name') Name
input(id='name', name="name",type='text',value='',placeholder='Type your name')
+
+ label(for='age') Age
+ input(id='age', name="age",type='text',value='',placeholder='Type your age')
+
input(type='submit',value='Send!')
View
9 express-example/views/test.jade
@@ -1,9 +0,0 @@
-html
- head
- body
- h1|Hello
- span=name
- p|Your Id:
- =id
-
-
View
4 yaap/wire/express/plugins/VerbProcessors.js
@@ -82,8 +82,10 @@ function(when, _) {
function processResponse(result, res, fnDescription, context){
- //raw json?
+ //raw?
if (getAnnotation(fnDescription, "@Body") !== undefined){
+ res.send(result);
+ } else if (getAnnotation(fnDescription, "@JSON") !== undefined){
res.json(result);
} else { //forwarding to view
if (typeof result === 'string')

0 comments on commit c7a49d4

Please sign in to comment.