Request-Endpoint-Response (REPR) Pattern
Overview
The Request-Endpoint-Response (REPR) pattern is a simple but important concept in modern web and API design. The pattern is a way of describing how communication works in web applications and APIs.
At its core:
- A client makes a request
- The request is sent to a defined endpoint (a URL or route)
- The server processes the request and sends back a response
This is the fundamental interaction model for REST APIs, web services, and most HTTP-based systems.
How It Works
1. Request
- Sent by a client (browser, mobile app, backend service).
- Contains method (GET, POST, PUT, DELETE), headers, and sometimes a body (e.g., JSON payload).
2. Endpoint
- A URL path on the server that defines what the request is targeting.
- Example:
/api/customers/123
β endpoint to retrieve customer with ID 123.
3. Response
- The server sends back data (JSON, HTML, XML, file, etc.) or status codes (e.g.,
200 OK
,404 Not Found
,500 Server Error
).
Advantages
- Simplicity: Clear flow of request β endpoint β response.
- Consistency: Clients always know what to expect.
- Scalability: Easy to extend by adding new endpoints.
- Interoperability: Works with any client that speaks HTTP (browsers, apps, services).
Drawbacks
- Rigid structure: Not ideal for highly dynamic interactions (e.g., streaming, real-time).
- Overfetching/underfetching: Fixed endpoints may not return exactly what the client needs (GraphQL addresses this).
- Statelessness: Each request is independent; maintaining state requires extra effort (sessions, tokens, etc.).
Example in C# (.NET Web API)
[ApiController]
[Route("api/[controller]")]
public class CustomersController : ControllerBase
{
// Endpoint: GET /api/customers/123
[HttpGet("{id}")]
public IActionResult GetCustomer(int id)
{
var customer = new { Id = id, Name = "Alice", Email = "alice@example.com" };
// Response: 200 OK with JSON data
return Ok(customer);
}
}
Flow:
- Request:
GET /api/customers/123
- Endpoint:
api/customers/{id}
handled byGetCustomer
- Response:
200 OK { "id": 123, "name": "Alice", "email": "alice@example.com" }
When to Use the REPR Pattern
- When building REST APIs or HTTP-based services
- For CRUD operations (Create, Read, Update, Delete)
- When you need a standard, predictable interaction model
For more complex, real-time, or flexible querying needs, alternatives like GraphQL or WebSockets may be better.
Summary
The Request-Endpoint-Response (REPR) pattern is the backbone of REST APIs and web apps: a client sends a request to a defined endpoint, and the server returns a response. Itβs simple, scalable, and universal for HTTP communication.