CampusLearn
← CSC 314 Web Application Technologies

Web Architecture, HTTP Protocol, and RESTful Services

Notes

Introduction to Web Architectures Modern web application development relies heavily on the multi-tier client-server architectural model. In this setup, client devices such as web browsers or mobile applications send requests across a network to remote servers that process logic and persist data. Understanding this separation of concerns is fundamental for third-year computer science students. The presentation layer handles user interface rendering, the application layer manages domain logic, and the data layer handles relational or non-relational databases. The HTTP Protocol and Lifecycle The Hypertext Transfer Protocol (HTTP) serves as the foundation of data exchange on the World Wide Web. HTTP is an application-layer, stateless request-response protocol. Because it is stateless, each transaction is treated independently without inherent memory of previous requests. A standard transaction begins when a client establishes a TCP connection and issues an HTTP request message containing a method, request target, headers, and an optional body. The server processes this request and returns an HTTP response containing a status code, response headers, and the resource payload. Common HTTP methods include GET for data retrieval, POST for resource creation, PUT and PATCH for updates, and DELETE for resource removal. Principles of RESTful Design Representational State Transfer (REST) is an architectural style designed around network resources. REST services communicate over HTTP using standard conventions. Key architectural constraints include statelessness, uniform interface, client-server independence, and cacheability. In RESTful design, endpoints represent nouns rather than verbs, and HTTP status codes communicate execution status. For example, status codes in the 200 series represent success, 400 series denote client errors, and 500 series indicate server-side faults. Practical example Consider an engineering team building an integration with the Safaricom Daraja M-Pesa API for an e-commerce platform based in Nairobi. When a customer initiates a Lipa Na M-Pesa transaction, the e-commerce client issues an asynchronous HTTP POST request to the internal backend endpoint /api/v1/payments/stk-push. The backend validates the Kenyan mobile phone format, constructs an authenticated HTTP POST payload containing the business shortcode, passkey, and transaction amount, and forwards it to Safaricom's public Daraja gateway. Safaricom acknowledges receipt with a 200 OK status code containing a MerchantRequestID and CheckoutRequestID. Because HTTP is stateless, the merchant server maps these transaction identifiers to the pending order record in a PostgreSQL database. Once the customer enters their PIN on their handset, Safaricom sends an HTTP POST webhook callback to the merchant server endpoint /api/v1/payments/callback. The merchant server inspects the ResultCode inside the callback body, updates the database record to marked as paid, and returns an HTTP 200 acknowledgement to Safaricom.

Quiz

1. In a RESTful architecture, which HTTP status code should be returned when a new resource is successfully created?

2. Which HTTP method is idempotent and conventionally used to replace an entire resource representation in RESTful services?

3. What does it mean for the HTTP protocol to be stateless?

Sign in to submit and securely grade your quiz.