🌐 How Web Applications Worked Before REST APIs: A Journey Through Servlets, JSP, and CGI

Before the world was introduced to REST APIs, web applications followed a very different approach for handling client requests and generating responses. Let’s take a short trip back in time to understand how things worked in the early days of web development — with technologies like CGI scripts, Java Servlets, and JSP (JavaServer Pages) leading the way.


🧩 The Early Era: CGI Scripts

Before Java and REST APIs became mainstream, developers used Common Gateway Interface (CGI) scripts to process requests.
CGI scripts were simple programs written in languages such as Perl, Python, or C, which ran on the web server every time a user sent a request.

How it worked:

  • The web server received a request (for example, when a user submitted a form).

  • The server executed a CGI script as a separate process.

  • The script generated a response (usually in HTML) and sent it back to the client’s browser.

Limitations of CGI:

  • Every request started a new process — which consumed more memory and CPU.

  • Handling concurrent users was inefficient.

  • It lacked reusability and was hard to maintain as applications grew complex.

These drawbacks eventually led developers to look for a better, more scalable solution.


☕ The Rise of Java Servlets

When Java entered the web development world, it brought Servlets, which revolutionized server-side programming.
A Servlet is a Java class that runs inside a Servlet container (like Apache Tomcat) and handles HTTP requests and responses.

How Servlets improved web development:

  • Instead of starting a new process for each request, Servlets used a single instance with multiple threads, making them faster and more efficient.

  • Servlets could maintain sessions, allowing personalized experiences for users.

  • They supported reusable and modular code, which made maintenance easier.

Typical Servlet Flow:

  1. A client sends an HTTP request.

  2. The web server forwards it to the Servlet container.

  3. The container invokes the appropriate Servlet.

  4. The Servlet processes the request (for example, by accessing a database).

  5. It generates an HTTP response (usually HTML or JSON) and sends it back.


💻 Dynamic Web Pages with JSP (JavaServer Pages)

While Servlets handled logic efficiently, writing HTML inside Java code quickly became messy.
To solve this, JSP (JavaServer Pages) was introduced — a technology that allowed developers to embed Java code directly inside HTML.

JSP made web development easier by:

  • Allowing separation of business logic (handled by Servlets) and presentation (handled by JSP).

  • Supporting tag libraries and Expression Language (EL) for cleaner code.

  • Making it easy to create dynamic content (like user-specific dashboards or form responses).

Essentially, JSP worked as a front-end layer, while Servlets acted as the back-end controller — a pattern that still influences modern frameworks today.


⚙️ From Servlets and JSP to REST APIs

Over time, web applications became more complex, and the need for standardized communication between client and server increased.
That’s where REST (Representational State Transfer) APIs came in.

How REST APIs changed everything:

  • They use HTTP methods (GET, POST, PUT, DELETE) for predictable operations.

  • Responses are often in JSON, making them lightweight and easy to consume.

  • REST allows frontend and backend separation, enabling frameworks like React, Angular, and Vue to communicate seamlessly with backend services.

In short, REST APIs made it possible for any client — mobile app, web app, or even IoT device — to interact with servers in a consistent, scalable way.


🔁 Summary: Then vs. Now

FeatureBefore REST (CGI, Servlets, JSP)After REST (Modern APIs)
CommunicationServer-generated HTML pagesJSON/XML responses
ArchitectureTight coupling between frontend & backendLoose coupling (frontend-backend separation)
ScalabilityLimited by server-side renderingHighly scalable and reusable
PerformanceMultiple processes per request (CGI)Multi-threaded or stateless services
ReusabilityHard to reuse UI logicReusable across devices and platforms

🚀 Final Thoughts

Technologies like CGI scripts, Servlets, and JSP paved the way for today’s modern web architecture. They taught developers how to manage requests, build dynamic pages, and handle user sessions — laying the foundation for RESTful APIs and the frameworks that followed.

While REST APIs dominate modern development, understanding their origins helps us appreciate how far web technology has evolved — from simple CGI scripts to the dynamic, data-driven web we experience today.

Post a Comment

0 Comments