Hi all,

This is a request for ideas on good code organization for my application. 
I've been reading up on the preferred organization for web2py as well as 
typical REST HTTP conventions, and I'm trying to use some ideas of both 
where they make sense.

If I understand correctly, web2py takes more of a verb approach, where a 
URL maps to a controller and then an action, which has a corresponding 
view. Additional parameters for the action can be additions to the URL 
(e.g. /app/controller/action/arg1/arg2) or key/value pairs in a query, 
though parameters can also be passed through the HTTP request body (but I'm 
not as familiar with how to read these in using web2py. Typical REST HTTP 
conventions, however, seem to use URL structures identifying resources, 
i.e. using nouns and then letting the HTTP method map to what to do with 
that resource (e.g. GET or POST or DELETE /app/persons/5). Each HTTP method 
on the same URL would map to a different action, effectively, on that 
resource or type of resource. I see some overlap here, making me think I 
can find I nice mix, but it's not immediately clear in my mind. With that 
intro, here's my current code hierarchy:

models:
  - dbTables.py
  - object_a/object_a.py
      - create_a_type1()
      - create_a_type2()
      - update_a()
      - get_info_abt_a()
      - ...other functions the controller shouldn't touch, i.e., private 
functions
  - object_b/object_b.py
      - create_b()
      - rename_b()
controllers:
  - object_a.py
      - ...what do I put in here???
  - object_b.py
      - ...what do I put in here???

I organized the models folder that way so that any given call won't reload 
the entire models code base. If I wanted to go the route of REST design, I 
was thinking of maybe adding to controllers/object_a.py a couple of 
functions called type1() and type2(), then checking whether the request was 
a GET or POST or whatever to then call the appropriate function in the 
model. But then models/object_b/object_b.py only describes one resource, so 
it feels kinda tacky to put within controllers/object_b.py a function 
called object_b(), since then the URL to call that function would be 
/app/object_b/object_b/..., which is a redundant and doesn't make for a 
clean API.

On the other hand, I could do something like move all the public model 
functions into the corresponding controllers instead, but then the URLs 
would be verbs instead of nouns (aka resources), and I wouldn't be able to 
keep a concise API that overloads a URL with the different HTTP methods.

What are your thoughts?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to