You can download all the source code directly from here:
http://github.com/miguel/rest-microblog/tarball/master
for test:
cd miguel-rest-microblog*
GAEpath/dev_app_server.py .
I use this route to access the controller:
('/messages(|/.*)',MessagesController
and then in MessagesController there are the methods needed for REST
actions. In the get and post methods the program selects what action
has to be done:
#shows all the messages
#route: GET /messages
def list(self):
messages = Message.all()
messages.order("-date")
self.render('templates/index.html', messages=messages)
#shows the given message
#route: GET /messages/message_name
def show(self,message):
self.render("templates/showMessage.html", message)
#shows the new form
#route: GET /messages/new
def new(self):
self.render("templates/newMessage.html")
#shows the edit form
#route: GET /messages/:message_name/edit
def edit(self,message):
self.render("templates/editMessage.html", message)
#creates the message and puts it into the datastore
#route: POST /messages
def create(self):
if self.request.get('name'):
message=Message(name = self.request.get('name') ) #new
message
if users.get_current_user():
message.user = users.get_current_user()
message.content = self.request.get('content')
message.put()
self.redirect('/messages/'+
message.name) #redirects to
list
else:
self.response.out.write('<div class="message"><b>ERROR:</
b> message name is empty.</div>')
#updates the given message
#route: PUT /messages/message_id
def update(self,message):
message.name = self.request.get('name')
message.content = self.request.get('content')
message.put()
self.redirect('/messages/'+
message.name) #redirects to show
#deletes the given message
#route: PUT /messages/message_id
def destroy(self,message):
message.delete();
self.redirect('/messages') #redirects to list
I don't have an account, so i can't test in the real environment.
Miguel.