This last week I build a very simple Sinatra “Hello World” application in which a user had to submit a bit of their information via a form. One of the things the user had to do is attach a file to this form. I did a bit of research on the behind the scenes stuff - what actually happens when a user interacts with your web applications and more specifically when it involves filling out forms. Pretty boring stuff but important when it comes to building web applications - even static pages. I consulted the HTTP RFC document and the MDN documents for the research. Here are some basic key points I found useful.
HTTP - Hypertext Transfer Protocol
A request/response protocol in which clients and servers communicate/exchange data. In the simplest terms a client sends a request to a server in the form of a request method via a Web browser and the server sends a response back to the client.
The request - GET/POST
GET request:
- Browser asks server to send back a given resource.
- Data in forms gets appended into name/value pairs.
- Number of name/value pairs depends on how many pieces of data you send.
- User can see the data in their URL (therefore do not send sensitive information).
POST request:
- Browser asks the server for a response based on the data provided in the body of the HTTP request. E.g. posting the value of an HTML form.
- Data in forms gets appended to the body of the request.
- User cannot see the data in the URL.
- Preferred method of sending large amounts of data as some browsers/servers do not accept large URLs.
The response - Server side
- The server can be a single machine or several servers can be hosted on the same machine.
- The server receives the data as a string.
- The string is then parsed to get the data as a list of key/value pairs. The way to access these key/value pairs depends on the development platform/framework.
- The server can manipulate the data in several ways:
- Display it
- Store it in a database
- Etc.
Proxy
comments powered by