Can you happily start a Web service? --1st step! Vernacular HTTP and code interaction that little thing ~

Source: Internet
Author: User
Tags mercurial

When we learn to write Python, we are more or less exposed to the Web program, but have you ever wondered what kind of thoughts and feelings are waiting for the backend code to receive the request when the browser sends an HTTP request?

Just like in this picture below, the back end may be a Java code, maybe php code, and of course, if the code comes from my hand, the most likely is a Python code. It's like, when you send a message to a stranger on social software, the opposite person may be British, Indians may be a sheep or a dog ... So the question is, how do they know what you're talking about? of course, in the world of Web services there is no real complexity, we do not need to consider the background to receive the request is a sheep ... Let's take a look at what's going on between the URL and the code.

  

First, when we write a piece of code that can be accessed by HTTP, we create a webserver. It is not difficult to see that this is the browser and the Web server between the daily work, for the server, the 5 things to do, only the 3rd is based on the different requests are changed:

  

 

Therefore, in the spirit of decoupling the idea, someone put forward a new scheme, the server-side repeatedly do things independently, packaged up, for programmers, we only need to focus on processing the request part, there is a special logic for us to deal with this perpetual 4 steps, is not to make the code a lot of concise?

However, when we do this, the server and app are no longer tightly bound together, the server must know what to say about the received request, how the parameters are communicated to the app side, which is what we can use Request.method, request in Django. Post.get and other methods of the reason--about good ah, said tall on a little, this convention is called the Agreement !

  

Is what we often do when we write Django, the left is an HTTP request, the right is the Python code, we just need to write a function in the code, URL with a match, you can use the URL to the left of the request to the backend code, why so smooth, What makes the generation gap between HTTP and Python code disappear?

   

  

  

With the Django framework as an example, what does Django do in this process? It is very intimate to the entire server to do things and the server and app interaction process to encapsulate it ~ ~ ~

In that case, Django is a model parent to our code, a father and a mother!

  

Of course! In addition to Django, Python has a lot of other web frameworks, modules have done the same encapsulation, they can also analyze the HTTP request, and assume the responsibility of the background code interaction, but we know that people even communicate the same thing there are many different ways of expression, so, We say that while HTTP and code interactions are also done, the definition of the protocol may vary.

Here are some common Python HTTP servers, along with their current general developments, so that the user can choose between:

Name Version HTTP 1.1 Flavour Repo. Community
Gunicorn 0.6.4 No Processor/thread Git #gunicorn
Uwsgi Trunk (253) Yes Processor/thread Repo Mailing List
FAPWS3 0.3.1 No Processor/thread Git Google Groups
Aspen 0.8 No Processor/thread Svn Google Groups
Mod_wsgi 3.1 Yes Processor/thread Svn Google Groups
Wsgiref Py 2.6.4 No Processor/thread Svn Mailing List
CherryPy 3.1.2 Yes Processor/thread Svn Planet, IRC
Magnum Py 0.2 No Processor/thread Svn Google Groups
Twisted 10.0.0 Yes Processor/thread Svn Community
Cogen 0.2.1 Yes Callback/generator Svn Google Groups
Gevent 0.12.2 Yes Lightweight threads Mercurial Google Groups
Tornado 0.2 Yes Callback/generator Git Google Groups
Eventlet 0.9.6 Yes Lightweight threads Mercurial Mailinglist
Concurrence Tip Yes Lightweight threads Git Google Groups

Reference: http://www.nowamagic.net/academy/detail/1330308

Can you happily start a Web service? --1st step! Vernacular HTTP and code interaction that little thing ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.