The Elegance of the Web: Simple Functions and Markup

Eric Okemwa
4 min readJan 1, 2024

--

The web, in all its complexity and diversity, is built upon a foundation of simple yet powerful principles. At its core, the interactions between clients and servers are governed by three fundamental functions: get(url), head(url), and post(url, form_data). Alongside these, the straightforward markup elements such as <a>, <form>, and <input> provide the structure for creating dynamic and interactive web content. Let's delve into the elegance of these basic building blocks that have paved the way for the expansive world of the internet.

The Functionality Trio: get, head, and post

1. get(URL) -> (status, headers, HTML)

Image by O’REILLY

The humble GET method is the backbone of resource retrieval. Whether fetching a webpage, an image, or any other resource, this function returns the status, headers, and HTML content. It forms the basis of our navigation through the vast landscape of the web.

2. head(URL) -> (status, headers)

In a Flask application, handling a HEAD request is similar to handling a GET request, as HEAD requests essentially ask for the same information but without the response body. Here’s how you can simulate a HEAD request and return a response with request headers:

from flask import Flask, request

app = Flask(__name__)

# Route for handling HEAD requests
@app.route('/head', methods=['HEAD'])
def handle_head():
# HEAD request should not include a response body
# Headers are still accessible using request.headers
headers = str(request.headers)
return '', 200, {'Headers': headers}

if __name__ == '__main__':
app.run(debug=True)

When you need information about a resource without fetching its entire content, the HEAD method steps in. It returns the status and headers, making it efficient for tasks like checking resource existence and retrieving metadata.

3. post(URL, form_data) -> (status, headers, HTML)

Image by O’REILLY

When it comes to submitting data, the POST method takes the stage. Whether it's a simple search query or a comprehensive form submission, this function enables the exchange of data between clients and servers.

The Markup Masters: <a>, <form>, and <input>

1. <a href={url}>

Image by BETA-Labs

The anchor tag, <a>, creates hyperlinks that connect different parts of the web. With the href attribute specifying the destination URL, it allows seamless navigation from one resource to another.

2. <form action={url}>

Image by HTMLGoodies

The <form> tag defines the structure for user input. With the action attribute pointing to the URL where the form data should be sent, it serves as the bridge for user interactions and server-side processing.

3. <input name={key}>

<form action=example-server.com">
<fieldset>
<legend>Contact me</legend>
<div class="form-control">
<label for="name">Name</label>
<input type="name" id="name" placeholder="Enter your name" required />
</div>

<div class="form-control">
<label for="email">Email</label>
<input
type="email"
id="email"
placeholder="Enter your email"
required
/>
</div>

<div class="form-control">
<label for="message">Message</label>
<textarea
id="message"
cols="30"
rows="10"
placeholder="Enter your message"
required
></textarea>
</div>
<input type="submit" value="Send" class="submit-btn" />
</fieldset>
</form>
Image by Freecodecamp

Within a form, the <input> tag takes center stage. By assigning a name attribute, it becomes a vessel for user input, ready to be submitted along with the form.

The Elegance Unveiled

What makes these functions and markup elements elegant is their simplicity. In an era of ever-evolving web technologies, these foundational principles have endured. They form the backbone of the web, enabling developers to create diverse, interactive, and dynamic content.

The elegance lies in the versatility these functions and markup elements offer. From the simplicity of a hyperlink to the complexity of form submission, the basic building blocks empower developers to create a wide array of web applications. They serve as the common language that allows seamless communication between clients and servers.

As we navigate the intricate web of interconnected resources, it’s essential to appreciate the elegance of its simplicity. These functions and markup elements, though basic, are the unsung heroes that make the web the dynamic and interconnected space that it is today. Embracing the elegance of the fundamentals is key to understanding and mastering the ever-evolving landscape of web development.

--

--