by teej · 15y ago · 0 comments
In the Ruby world if I want to use the awesome library Sass all I have to do is:
gem install sass
Because it functions as a Rack plugin it automatically works with any Ruby web framework & Ruby web server combo I choose. No special setup required.-----
# WSGI
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
yield 'Hello World\n'
# Rack
app = proc do |env|
[ 200, {'Content-Type' => 'text/plain'}, "a" ]
end
WSGI is the Rack for Python. In fact, WSGI predates Rack, and Rack is WSGI inspired. # Pump
def app(request):
return {
"status": 200,
"headers": {"content_type": "text/plain"},
"body": "Hello World"}I understand your point that web developers don't necessarily work with WSGI on a day-to-day basis. But if you look at the Ruby web community, Rack middlewares are much more prevalent than WSGI middlewares. Application developers (as opposed to framework developers) often add functionality as a Rack middleware, so that it can be reused in different applications, even using different frameworks. Why isn't that happening with Python as much? In the Python world, instead of writing even simple middlewares to for basic functionality like https://github.com/adeel/pump/blob/master/pump/middleware/pa... or https://github.com/adeel/pump/blob/master/pump/middleware/co..., every framework ends up reimplementing it. I believe this is because the WSGI API is ugly and not as easy to understand as it could be (just look at the average WSGI middleware).
public class App extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
response.getWriter().println("Hello world");
}
} # hello.cgi
print "Hello World\n";
I wasn't trying to claim WSGI is the first web server to application server interface. I was just showing Rack and WSGI are similar, and Rack was WSGI inspired.I don't think anyone other than wsgi library implementors code to WSGI. WSGI would be a problem if that's how python web programming was to be done - but that's not the case.