Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis cellularmitosis/README.md

Last active Oct 15, 2019
Embed
What would you like to do?
Dictionary-in, Dictionary-out style with WSGI

Blog 2019/3/8

<- previous | index | next ->

Dictionary-in, Dictionary-out style with WSGI

A trivial WSGI app which tries to make WSGI a bit more like Clojure's Ring framework (dictionary-in, dictionary-out).

def root_endpoint(request):
d = {}
d["status"] = '200 OK'
d["body"] = 'Root!\n'
d["headers"] = [
('Content-type', 'text/plain'),
('Content-Length', str(len(d["body"])))
]
return d
def hello_endpoint(request):
d = {}
d["status"] = '200 OK'
d["body"] = 'Hello, world!\n'
d["headers"] = [
('Content-type', 'text/plain'),
('Content-Length', str(len(d["body"])))
]
return d
routes = {
"/": root_endpoint,
"/hello": hello_endpoint
}
def route(request):
return routes[request["PATH_INFO"]]
def application(request, start_response_fn):
handler = route(request)
response = handler(request)
start_response_fn(response["status"], response["headers"])
return [response["body"]]
sudo pip install mod_wsgi
mod_wsgi-express start-server ring.wsgi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.