Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 199 lines (134 sloc) 6.254 kb
5bc448a @creationix Port geddy article from node knockout.
authored
1 Title: An Introduction to Geddy
2 Author: Matthew Eernisse
3 Date: Sat Sep 11 2010 17:02:05 GMT-0700 (PDT)
4 Node: v0.2.1
5
6 This was the fifth in a series of posts leading up to
7 [Node.js Knockout][] on how to use [node.js][]. This post was
8 written by [geddy][] author and [Node.js Knockout judge][] Matthew
9 Eernisse.
10
11 Geddy is a modular, full-service web framework for Node.js, similar
12 to Merb, Rails, Pylons, or Django.
13
14 Geddy provides a lot of great features:
15
16 - Flexible, robust router with easy RESTful routing
17 [(router docs)][]
18 - Intelligent content-negotiation [(content-negotiation docs)][]
19 - Models and validations[(model docs)][]
20 - Simple, intuitive views with partials support
21 - Generator utility for easy creation of apps and scaffolding
22
23 ## Installation
24
25 There are a few different ways of getting Geddy.
26
27 Download the current release, [geddy-v0.1.1.tar.gz][] (2010-08-06)
28
29 $ ~/work$ curl -O http://geddyjs.org/dist/geddy-v0.1.1.tar.gz
30 $ ~/work$ tar -xvzf geddy-v0.1.1.tar.gz
31 $ ~/work$ cd geddy-v0.1.1
32 $ ~/work$ make && sudo make install
33
34 Or, get the latest Geddy code from GitHub and install it:
35
36 $ ~/work$ git clone git://github.com/mde/geddy.git
37 $ ~/work$ cd geddy
38 $ ~/work$ make && sudo make install
39
40 Geddy can also now be installed with NPM:
41
42 $ npm install geddy
43
44 If you want to use a database, you'll need database bindings for
45 Node (The Geddy GitHub wiki has docs for setting up [SQLite][] or
46 [Postgres][]). CouchDB does not require database bindings.
47
48 NOTE: For Postgres, your database user must have the ability to
49 create databases and tables.
50
51 ### Create an app
52
53 Create your Geddy app:
54
55 $ ~/work$ geddy-gen app bytor
56 Created app bytor.
57
58 Check if your app runs:
59
60 $ ~/work/bytor$ geddy
61 Geddy worker (pid 5206) running at port 4000 (development mode)
62
63 Go to [http://localhost:4000/][] — you should see the following:
64
65 “Attention all planets of the Solar Federation”
66
67 Geddy has some startup options you can see by doing `geddy -h` or
68 `geddy --help`.
69
70 ## RESTful routes
71
72 Create a resource-based route with a model stub using
73 `geddy-gen resource [model_name]`:
74
75 $ ~/work/bytor$ geddy-gen resource snow_dog
76 [ADDED] ./app/models/snow_dog.js
77 [ADDED] ./app/controllers/snow_dogs.js
78 resources snow_dogs route added to ./config/router.js
79 Updated inflections map.
80 Created view templates.
81
82 Geddy's pluralization code isn't that smart yet — if you want a
83 special plural, add it with a comma after the model name (e.g.
84 `geddy-gen resource foo,fooes`).
85
86 There is a nice [wiki doc for Geddy's router][(router docs)].
87
88 Test your RESTful routes:
89
90 $ ~/work/bytor$ geddy
91 Geddy worker (pid 5206) running at port 4000 (development mode)
92
93 Go to [http://localhost:4000/snow\_dogs.html][]. You should see the
94 following:
95
96 Params
97
98 - extension: html
99 - controller: SnowDogs
100 - action: index
101 - method: GET
102
103 This is just printing out the contents of the `params` object in
104 the action.
105
106 Now go to [http://localhost:4000/snow\_dogs.json][]. You should see
107 the following:
108
109 {"params":{"method":"GET","controller":"SnowDogs","action":"index","format":"json"}}
110
111 This is Geddy's content-negotiation at work. Geddy tries to do the
112 right thing based on the formats your controller supports, and what
113 the client wants.
114
115 There is more detailed info on
116 [Geddy's content-negotiation in the wiki doc][(content-negotiation docs)].
117
118 ## Model properties, etc.
119
120 Kill the server (Ctrl+c), and change your model as desired.
121
122 $ ~/work/bytor$ vi app/models/snow_dog.js
123
124 Add some properties, validations, methods:
125
126 <introduction-to-geddy/models/snow_dog.js>
127
128 [The wiki doc on models][(model docs)] has more detailed info.
129
130 ## DB config
131
132 Turn on database support. Edit your development config file:
133
134 $ ~/work/bytor$ vi config/environments/development.js
135
136 Set the appropriate values in config.database. See the wiki doc on
137 [sample DB configs][] for examples.
138
139 Create the database.
140
141 (Remember, with Postgres, your database user has to have enough
142 privileges to create a database.)
143
144 $ ~/work/bytor$ geddy-gen db:create
145 Creating DB for development.js...
146
147 ## Scaffold
148
149 Generate your scaffold from the model file you just edited:
150
151 $ ~/work/bytor$ geddy-gen scaffold snow_dog
152 Created client-side model JavaScript files.
153 Created controller and views for snow_dog.
154
155 Fire up the server again:
156
157 $ ~/work/bytor$ geddy
158 Geddy worker (pid 5206) running at port 4000 (development mode)
159
160 Go to [http://localhost:4000/snow\_dogs.html][], and start
161 creating, editing, removing items.
162
163 That’s pretty much it.
164
165 The query API for Geddy's models is still pretty limited — it
166 supports only find-by-id and find-by-type. You can take a look at
167 the code in your controller for a closer look at the API.
168
169 ## Get involved
170
171 You can help out with Geddy by filing bug reports on GitHub here:
172
173 [http://github.com/mde/geddy/issues][]
174
175 If you have questions, problems, or feature ideas, you can shoot an
176 e-mail to the mailing list here:
177
178 [http://groups.google.com/group/geddy][]
179
180 And of course, you can always [fork Geddy on GitHub][], make
181 improvements, and send a pull request.
182
183 [Node.js Knockout]: http://nodeknockout.com/
184 [node.js]: http://nodejs.org/
185 [geddy]: http://geddyjs.org/
186 [Node.js Knockout judge]: http://nodeknockout.com/judging#matthew_eernisse
187 [(router docs)]: http://wiki.github.com/mde/geddy/using-the-router
188 [(content-negotiation docs)]: http://wiki.github.com/mde/geddy/content-negotiation
189 [(model docs)]: http://wiki.github.com/mde/geddy/models
190 [geddy-v0.1.1.tar.gz]: /dist/geddy-v0.1.1.tar.gz
191 [SQLite]: http://wiki.github.com/mde/geddy/install-sqlite-and-node-sqlite
192 [Postgres]: http://wiki.github.com/mde/geddy/install-postgresql-and-node_postgres
193 [http://localhost:4000/]: http://localhost:4000/
194 [http://localhost:4000/snow\_dogs.html]: http://localhost:4000/snow_dogs.html
195 [http://localhost:4000/snow\_dogs.json]: http://localhost:4000/snow_dogs.json
196 [sample DB configs]: http://wiki.github.com/mde/geddy/sample-db-configs
197 [http://github.com/mde/geddy/issues]: http://github.com/mde/geddy/issues
198 [http://groups.google.com/group/geddy]: http://groups.google.com/group/geddy
199 [fork Geddy on GitHub]: http://github.com/mde/geddy
Something went wrong with that request. Please try again.