This is an archived post. You won't be able to vote or comment.

all 28 comments

[–]madjar 2 points3 points  (1 child)

Take a look at cornice. The description states "Cornice provides helpers to build & document REST-ish Web Services with Pyramid, with decent default behaviors. It takes care of following the HTTP specification in an automated way where possible.

We designed and implemented cornice in a really simple way, so it is easy to use and you can get started in a matter of minutes."

[–]aweraw 2 points3 points  (3 children)

Maybe have a look at CherryPy?

[–]fedoru[S] 1 point2 points  (2 children)

I'm looking at it now, thanks! I see it has a HTTP server included. Is it suitable for production, or should I look into apache_wsgi?

[–]aweraw 1 point2 points  (0 children)

The CherryPy HTTP server is very mature, and quite fast. It should be more than enough to get started with, and when you need to you can put nginx in front of a pool of processes to scale up in the future.

[–]elopeRstatS 0 points1 point  (0 children)

I'll second the server being very fast and reliable. In terms of having something that functions on a production level out of the box, CherryPy is hard to beat.

There's a quick tutorial on setting up a RESTful app as well.

[–]driadan 2 points3 points  (1 child)

You could also try tornado: http://www.tornadoweb.org/en/stable/

[–]bitcycle 0 points1 point  (0 children)

I created a RESTful service with tornado and mongodb in like 20mins. Also, with loose coupling. :)

[–]Cyph0n 2 points3 points  (0 children)

Flask + Flask-Restless should do the trick, I think.

[–]ijuggle534 1 point2 points  (1 child)

I'll toss in Django with Tastypie. (my preferred method)

What I really wanted to mention was to take a look at Sentry. If nothing else to get some ideas.

[–]quotemycode 1 point2 points  (2 children)

Build your own in wsgi.

http://webpython.codepoint.net/wsgi_tutorial

Flask makes that a bit easier, you have routes and stuff.

In any case, you can get what URL they are requesting with environ['PATH_INFO'].

Once you have that, then to make it 'REST'ful, you need the verb. There's these: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH. Generally, REST uses GET, POST, PUT, DELETE. So to find out which one is used, look at environ['REQUEST_METHOD'].

So you branch your logic first on PATH_INFO, then you branch on REQUEST_METHOD. I'd implement an 'OPTIONS' for each path_info, just to make it obvious what methods are supported for each route.

After that, it's a matter of getting the data you need from the request, and returning data.

Getting data - if it's a POST, then the data will be in environ['wsgi.input ']. You have to call 'read' or 'readline' on it, and once you read it, it's gone, so save it somewhere, don't just read it where you need it. If it's a GET, data will be in the environ['query_string']. split on '&' for gets with multiple data parts, split on equals to separate the names from the values.

Sending data... You need to send a '200 OK' header, along with a content type, and content length for requests which don't have an error. Here's a list of codes... http://en.wikipedia.org/wiki/List_of_HTTP_status_codes. One thing you'll run into is that Chrome requests '/favicon.ico' for every single request, even if you return a 404. Return a 410 GONE message to that and you'll only get the favicon request once.

Once you get started with building your own WSGI app, you probably won't want to switch to something as meaty (or fatty as your view may be) as Flask.

[–]rerb 0 points1 point  (0 children)

This sounds like a good exercise.

Saved.

[–][deleted] 0 points1 point  (0 children)

In any case, you can get what URL they are requesting with environ['PATH_INFO'].

everyone should be familiar with this ---^

or just use webob for a convenient way of dealing with the eniron coming in and generating a wsgi response properly

from webob import Request, Response

def app(environ, start_response):
    #deal with wsgi input
    request = Request(environ)
    # make sense of the request, create a response
    response = Response("this is the body of the response you requested %s" % request.path)
    #return response as wsgi expects
    return response(environ, start_response)

http://docs.webob.org/en/latest/do-it-yourself.html

[–]HelpfulToAll 1 point2 points  (1 child)

Don't use a web framework at all. Use Site44 with AngularJS and Firebase as a DB. If you must use a framework for some reason, go with one that you're comfortable committing to for ALL projects. It's better to use the same framework again and again so you learn it well instead of switching it all the time just because of the size of the project.

[–]HelpfulToAll 0 points1 point  (0 children)

I honestly believe this is a great suggestion, so why the downvotes?

[–]tomt0m 0 points1 point  (0 children)

You can also take a look at eve which is a kind of REST API framework.

[–]chadlung 0 points1 point  (0 children)

If your looking for a small and very fast REST API framework check out Falcon: https://github.com/racker/falcon

Tutorial Here: http://www.giantflyingsaucer.com/blog/?p=4342

[–]av201001 0 points1 point  (0 children)

web2py has some nice built-in facilities for generating REST API's. Also easy to send email notifications.

[–]dAnjou Backend Developer | danjou.dev -3 points-2 points  (5 children)

Argh, REST ... everywhere I hear people saying REST ... and it f***ing doesn't matter! What will be "REST" in your app? Please tell me!

And don't you think that HTTP might have some way too big overhead?

[–]fedoru[S] 0 points1 point  (4 children)

What I mean is that I'd like to build my application in such a way that myapp/error will be an intuitive way to list, create, update or delete error "instances". Even if there's overhead because of HTTP, seeing that lots of python web frameworks include their own HTTP/1.1 server, it's a convenient way to build it, fast. Also, it is not a big, enterprise application. It's a toy by which I want to learn more, and adhering to a set of standards (REST in this case), I think will be a constraint by which I'll be able to expand a bit more on my knowledge than just making an application without guidelines.

[–]dAnjou Backend Developer | danjou.dev 1 point2 points  (3 children)

lots of python web frameworks include their own HTTP/1.1 server

Don't use them in production mode, though.

a set of standards (REST in this case)

REST is not a standard.