Webware for Python
How to create RESTful URLs

How to create RESTful URLs

information

REST, Representational State Transfer, is a means of creating very nice URLs. When
using REST, the URLs will be clean, readable, and any person wishing to request
information can use them. i.e. If you have a dictionary site, and you wish to provide clean easy access, simply design using REST.

examples
“http://localhost:8080/lookup/python”
“http://localhost:8080/lookup/machine”

important code
ExtraPathInfo = True
self.request().extraURLPath()

downloads
zip tar.gz

tutorial
run the command

./Webware/bin/MakeAppWorkDir.py Restful

open Configs/Application.config
change ExtraPathInfo to True
create a file named View.py in MyContext

View.py:
from WebKit.Page import Page
import os

class View(Page):
  def title(self):
    return 'RESTful URL'
  def writeContent(self):
    item = self.request().extraURLPath()
    if os.path.exists('MyContext' + item + '.txt'):
      f = open('MyContext' + item + '.txt','r')
      self.writeln(f.read())
    else:
      self.writeln('this is the default page')


create the files webware.txt
webware.txt

Webware for Python rocks!

wolfeon.txt

Wolfeon is a company focused on developing productive technology

Now, run the application by running the command
./AppServer

You'll now be able to load the created text files by using RESTful URLs
http://localhost:8080/View/webware
http://localhost:8080/View/wolfeon


Using SQLObject and KidKit




Valid XHTML 1.0 Strict