How to limit web frames

This is a general question about how limited web development frameworks such as Django and ruby-on-rails are.

I plan to create a RESTful web service that will have a pure JSON / XML interface, without a GUI. The service will rely on the database, however for some more important operations there is no clear way to save the "model" object directly in the database table. In addition, I demand full control over when and how data is written to the database. I will need to support multiple database connections in order to use some read-only connections and others write-only.

I reviewed the "full" MVC frameworks like Django and simpler ones like web.py and pylons. The impression that I now have is that if I go with a full map, everything will go faster at first, but in the end I got stuck, because I will limit myself to what I can do. If I go with a more basic structure, it will take a long time for it to work, but I will be free to do what I need.

This is what it seems, but I suspect it might be a wrong impression, given how many sites are written in Django and Rails. Could you express your opinion. I'm completely wrong, and there is a way to easily do something with a framework like Django or Rails, or according to my requirements. Do I need to go with something like web.py?

Thanks!

+7
python rest django ruby-on-rails
source share
11 answers

Web structures are typically optimized around the creation of websites, which simplifies the implementation of most common use cases. After you start to do more out of the box with the framework, you may find that you spend more time working on it, and then save it first.

It is difficult to generalize here (especially since I really only worked with Django), so I will give some tips based on my own experience in developing the JSON API using Django:

Simple put, I do not recommend using Django to write a REST API. In my own experience, I really did not find anything worth writing about. I don't need the Django template system, so all I really used was the URL manager and ORM. Even then, I had to do some hacks to get the URL manager to do what I wanted - if I hadnโ€™t used other functions that would have used a different URL system faster. In your case, Django ORM doesn't even work, as it does not support multiple databases (unless you use 1.2 alpha ...). The mix that with Django is the lack of a good trigger, and Django is starting to look pretty bad for work.

If I were in your power, I would dig for specific libraries that did what I needed (ORM, WSGI, etc.), and simply used them, instead of trying to bend and hammer Django into anything that fits my needs.

In a completely different note, you can take a look at Tornado as a possible HTTP interface. It is simple and fast.

+8
source share

Most websites will work well for rich frameworks like Rails or Django, but you are creating a web service and this has very different tradeoffs.

Personally, I prefer to use very lightweight frameworks for web services: in Python, this basically means WSGI (which is a standard, not a framework), with minimally modular components, to provide some small additional features that I might need in depending on the details of the services (WSGI is very good at resolving the modular composition of "middleware").

My personal favorite collection of WSGI Werkzeug modular components, WebOb for request and response objects; if I need templates, these days I'm leaning towards Django templates , and if I need a relational database, I prefer to write SQL directly (although SQLAlchemy has its strengths! -).

But the cool thing about using modular components rather than integrated frameworks is that you can change each of these options (and mix-and-match as you wish, depending on your exact needs, preferences and tastes!).

+6
source share

You can still use the full potential of the language in question, even if you also use the framework. The framework is not a limiting factor; it is basically a tool to facilitate the development of certain parts of your application. For example, Django and rails abstract some database functions, so you only have to worry about your model objects. This does not mean that you cannot do things on your own ...

+5
source share

On average, the more complete and useful the web infrastructure is, the more limited it is when you try to do something different than what the web structure thinks is the right way. Some web frameworks try to be very useful and still not restrictive, and some do it better than others.

And the general recommendation is: Do not fight with the frame. You will lose. Therefore, it is important to choose a structure that will help you in what you want to do, but does not provide anything else. For your webservice business this should not be a problem. There are tons of minimalistic web frameworks there, at least in the Python world (and thatโ€™s all I care about). Bobo, BFG, Pylons, Werkzeug etc. Etc. None of them will do you one bit.

Also, remember that you can often use several frameworks together, making them work side by side. Especially using techniques such as Dexterity / XDV. For example, Plone.org is basically Plon (duh) a great content management system, but extremely restrictive if you want to do something else. So part of the site is Trac, a great Python error debugger. All of this is integrated to look the same.

+2
source share

Rails is useful or not as you need it in general. If you need to download a collection with direct SQL, it's simple. If on the same line you want to use all the built-in ActiveRecord Fu, you can. RESTful routing is extremely simple, but then again, if a particular Rails REST effect does not meet your needs, routing is fully customizable. In a Rails application, you can use as many or fewer defaults as you need, and reconfiguration is available at all levels.

+1
source share

If you are not using the Rails presentation layer, you will skip it on a huge part. The functionality needed to drop objects in json / xml is so small that the only real remaining advantages that you could get from it would be ActiveRecord and routing, and if you cannot present your data, a clean installation of the model, then this is not leaves a lot.

I think you really need a minimalist foundation to take care of some basics. Something that gives you some subtleties when processing requests and responding and routing, and gets out of your mind. For your lane, it might be the Python equivalent of something like Sinatra . I use a similar structure in Scala Step for xml / json-based web services, where I really like the performance (and there is no presentation below).

I am browsing web.py, it looks like it is like Sinatra / Step. I believe that this is a more suitable direction than some of the more complete functionality. I did not regret my choice of Step, the code base is so ridiculous that it is impossible not to understand, and this facilitates a small extension if you have a need.

+1
source share

I have been using Ruby / Rails for many years, and unlike all other languages โ€‹โ€‹/ frameworks that I have used (for almost 15 years of working with Java, PHP, ColdFusion, ASP, etc.), it gets out of the way when you need to do this.

It looks like you could use a โ€œlighterโ€ interface like Sinatra, but with the upcoming release of Rails 3, the benefits are becoming less pronounced. Rails 3 makes everything customizable ... in fact, Rails will now be just a specific set of plugins and extensions sitting on an infinitely flexible core.

I am interested in the following statement:

"The service will rely on the database, but for a few more important operations there is no clear way to save the" model "object directly in the database table."

Not sure what you mean by this statement ... at some point, something happens in your database, right?

In most non-trivial applications, you rarely have one model attached to the end of the request ... you can have a rather complex network of models that are returned or updated.

If you are working with JSON, I would definitely suggest looking at a database like MongoDB. MongoDB is entirely based on JSON data storage and therefore can be very neatly compatible with your application.

+1
source share

You did not indicate any requirements ; you wrote down technological solutions. This is something completely different. What do you want to achieve? Then we can help you with how to reach them.

+1
source share

If you know that you are not going to use ORM or create a user interface, then you have just ruled out about 90% of what you used as the basis for web applications. If you look at the Django feature set, for example: what parts of this would you use to implement a web service that you could not get from using something much simpler, like Werkzeug or CherryPy?

The main differences between building a web service and building any old black box that accepts input and outputs are the various technical limitations imposed by the HTTP-based APIs, the problem of statelessness, and the problem of idempotence. The web application framework will help you a little with these problems, but not much.

+1
source share

You will be much more limited by your own abilities and a diverse community of developers working on a large project to share all these common parts.

0
source share

Try Spring 3.0: See this post

0
source share

All Articles