Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added documentation for express-integration

  • Loading branch information...
commit c3ad218385d1d9467cfa8d48c1376140bf17b659 1 parent c0909c4
Peter authored

Showing 3 changed files with 35 additions and 1 deletion. Show diff stats Hide diff stats

  1. +1 0  README.md
  2. +22 0 yaap/README.md
  3. +12 1 yaap/docs/annotations.md
1  README.md
Source Rendered
@@ -8,6 +8,7 @@ See [Readme](yaap) for more information.
8 8 There are also two examples for server and client scenario:
9 9
10 10 * On [Node](node-example)
  11 +* With [Express.js] [Node](express-example)
11 12 * In [Browser](browser-example)
12 13
13 14
22 yaap/README.md
Source Rendered
@@ -6,6 +6,8 @@ Yaap is a generic annotation processor for javascript. It can be used to impleme
6 6 It [integrates](#wirejs-integration) with [wire.js](https://github.com/cujojs/wire) (part of [cujo.js](http://cujojs.com)), which enables Spring-style wiring (i.e. dependency injection) of your javascript applications.
7 7 With the `yaap/wire` plugin, @Autowired applications are possible
8 8
  9 +It also [integrates](#expressjs-integration) with Express.js to achieve a SpringMVC-style framework for webapps.
  10 +
9 11 `Remark:` This is an experimentational library and should not be used in production.
10 12
11 13 An overview of out-of-the-box supported annotations is available [here](docs/annotations.md)
@@ -17,6 +19,7 @@ Installation for node: `npm install yaap`
17 19
18 20 * [Annotations for JavaScript](http://cubiccow.blogspot.com/2013/02/yaap-annotations-for-javascript.html)
19 21 * [@Autowired for JavaScript](http://cubiccow.blogspot.de/2013/02/autowire-for-javascript.html)
  22 +* [Express.js the SpringMVC-way](http://cubiccow.blogspot.com/2013/04/expressjs-springmvc-way.html)
20 23
21 24 ##Example
22 25
@@ -115,3 +118,22 @@ module.exports = {
115 118 The yaap/wire plugin will be called after the bean was created. That means, the constructor itself will not be affected by annotations.
116 119
117 120 As a workaround, use a separate initialize-method (using the [init-facade](https://github.com/cujojs/wire/blob/master/docs/configure.md#init-methods) of wire).
  121 +
  122 +##Express.js integration
  123 +There are also out-of-the-box annotations included for creating webapps in a springMVC-like manner. A simple example of a service:
  124 +
  125 +```js
  126 +MyService.prototype = {
  127 + index: function ()/*@GET*/ {
  128 + return 'index';
  129 + },
  130 +
  131 + submit: function (name, age)/*@POST @Param*/ {
  132 + var msg = (age < 18)? "You are too young" : "You are welcome!";
  133 + return {view:'greet', model:{name: name, msg: msg}};
  134 + }
  135 +};
  136 +```
  137 +As known from SpringMVC, the returned values determine, which view will be called and with what parameters.
  138 +More details on this in my [blogpost](http://cubiccow.blogspot.com/2013/02/autowire-for-javascript.html).
  139 +
13 yaap/docs/annotations.md
Source Rendered
@@ -23,7 +23,7 @@ Some annotations can only be used on parameters while others can also be used at
23 23 * `@PreDestroy` (function): the annotated function will be called, if context.destroy() is called.
24 24
25 25 ###browser-specific wire annotations
26   -for these annotations, you need to add the additional `yaao/wire/html`-plugin!
  26 +for these annotations, you need to add the additional `yaap/wire/html`-plugin! (as shown in the browser-example)
27 27
28 28 * `@On(<refName>, <event>)` (function): the annotated function will automatically be bound the the event of the given dom-node.
29 29 This is intended to be used with the `wire/dom`-plugin. <refName> can reference one or more elements in the dom (though
@@ -31,3 +31,14 @@ for these annotations, you need to add the additional `yaao/wire/html`-plugin!
31 31 For example, you could bind a clickhandler with this annotation: `@On("dom.all!.btn","click")`.
32 32 The annotated method accepts one argument that is the event (though you could add additional @autowired arguments, if you want)
33 33
  34 +###Node-Specific wire-annotations (Express.js)
  35 +for these annotations, you need to add the additional `yaap/wire/express`-plugin! (and you need to feed the express-application into the plugin as shown in the express-example)
  36 +
  37 +* `@GET/POST/PUT/DELETE([<pathspec>])` (function): registeres the function as an endpoint in an express-application with either the given path
  38 + or the functionname as path, if omitted.
  39 +* `@Param([<name>])` (parameter/function): fetches the annotated parameter from the query/path/post parameters.
  40 + If annotation is on function-level, all parameters (except `@Body`-annotated parameters) are injected by-name.
  41 +* `@Body` (parameter/function): if parameter-level, then the request-body will be injected. If on function-level,
  42 + it states that the return-value will be returned as-is (Just like @ResponseBody does in SpringMVC).
  43 +* `@JSON` (function): states, that the returned value will be send as response in json-format. (using [response.json](http://expressjs.com/api.html#res.json)).
  44 +*

0 comments on commit c3ad218

Please sign in to comment.
Something went wrong with that request. Please try again.