I am not a native English speaker so if you find any grammar mistake, please let me know. That’s gonna really really helpful to me! 😀
How does the Web work?
We all use the internet, most of us, use this every day. But you know how does the web work exactly? It’s more complicated than you type google.com on your browser and press enter. This link will be helpful to know how the Internet works.
What is the Web Programming?
In short, web programming is developing server and client that communicate with HTTP(s) protocol. But we usually develope the server side only. Because we already have nice and neat web clients(web browsers) like Chrome and Safari, but still you can develope the client side if you want.
Let’s make an simple and primary client with Python and request the web page.
You can check the HTML response here. But you do not have to use a web browser to send requests to a web server.
This is curl command of Linux if you test this code then you can get the same response as before.
Now you know that can send a request as a Web client, even if it is not necessarily a Web browser.
The HTTP(Hypertext Transfer Protocol) protocol is the communication method used to send and receive data between the web server and the client. It’s work on the TCP/IP protocol. It means web server and web client should have an IP address for TCP/IP protocol.
If you type www.google.com on the web browser and press enter, then client/server connection through HTTP will work. Web client sends the HTTP request message and the web server handle the request and send the result to the client as an HTTP response. This is how the web works.
HTTP message structure
There are two types in the HTTP messages, one is the request message from the client to the server and the other is response message from the server to the client.
The start line called the request line when it’s a request message. When it’s a response message, it called the status message.
This is an example of the request message without a body. The first line is the request line that has the request method, request URL, and the protocol version. Second line is the header. You can skip the Host header if you want.
GET <https://www.example.com>::8080/book/shapespeare HTTP/1.1
Now let’s see the response message.
HTTP/1.1 200 OK
Content-Type: application/xhtml+xml; charset=utf-8
The first status line has the protocol version, status code, and status text. The server displays the processing results in the status line. In this case, the result is ‘200 ok’. Here we can see that the results have been processed normally.
HTTP request method
It tells the server how clients are handled via the HTTP method. There are 8 methods in the HTTP method. Of these, the most commonly used are GET, POST, PUT, DELETE. These match up to the CRUD.
This is one of the most common methods all of the 8 methods. This requests the data in the URL. Get is used to request data from a specified resource.
Get method sends the data attaching ‘name=value’ after ? in the URL. So, this method has length restrictions. And this remains in the browser history so you should never be used when dealing with sensitive data.
POST is used to send data to the server to create/update a resource/ This does not remain in the browser history and have no restrictions on data length.
In Python’s Django web framework, the data in the form is being dealt with only POST method.