I still think traversal-based resources lend themselves to RESTful mappings 
better than route-based routines.

GET /notes              # get a listting of all notes
POST /notes             # create a new note
GET /notes/firstnote    # get full information on the "firstnote" note
PUT /notes/firstnote    # change the details of the "firstnote" note
DELETE /notes/firstnote # delete the "firstnote" note

In this scenario, we would have traversal resources like this...

root                    # an instance of Root
root/notes              # an instance of NotesContainer
root/notes/firstnote    # an instance of Note

And then we would have views such as (what follows is pseudo code)...

@view_config(request_method='GET', context=NotesContainer)
def notes_listing(request):
    return {'notes': db.query(Note).all()}

@view_config(request_method='POST', context=NotesContainer)
def add_note(request):
    note = Note(**somevals)
    db.add(note)
    db.flush()
    return single_note(request, note.id)

@view_config(request_method='GET', context=Note)
def single_note(request, note_id=None):
    if note_id is None:
        note_id = request.context.__name__
    return {'note': db.query(Note).filter_by(Note.id==note_id}


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to