The Proxy is a structural design pattern that provides an object acting as a substitute for a real service object. The proxy receives client requests and performs additional work—such as access control or caching—before passing the request to the actual service object.
Conceptual Model: Nginx Proxy
A common real-world example is a web server like Nginx acting as a proxy for an application server. It provides:
- Controlled access to the application server.
- Rate limiting.
- Request caching.
Expected Execution Output
When running the example, you will see simulated HTTP requests and responses demonstrating access control (e.g., 403 Not Allowed) and successful service calls:
Url: /app/status
HttpCode: 200
Body: Ok
Url: /app/status
HttpCode: 200
Body: Ok
Url: /app/status
HttpCode: 403
Body: Not Allowed
Url: /create/user
HttpCode: 201
Body: User Created
Url: /create/user
HttpCode: 404
Body: Not Ok