[BSS-31] New Request Mechanism: A Structured and Flexible Approach #6
Closed
shahmal1yev
started this conversation in
Ideas
Replies: 1 comment
-
Development started in #9 🐘 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In this discussion, we introduce the "New Request Mechanism," a structured yet flexible solution for handling HTTP requests within our system. The new mechanism aims to simplify the process of building requests by providing a clear, extendable architecture that can be adapted to different types of requests with minimal overhead.
Objective
The primary goal of this new request mechanism is to offer a consistent and modular approach to building API requests. It ensures that request components such as headers, body, query parameters, and methods can be dynamically set and retrieved in a clean, reusable manner. Furthermore, this mechanism lays the groundwork for future enhancements while maintaining simplicity and ease of use.
Core Components
1. Request Class
The
Request
class is at the heart of this mechanism. It encapsulates the basic functionality needed to construct an HTTP request, such as setting headers, query parameters, body fields, and the HTTP method. It also manages the URI and offers a straightforward way to retrieve and manipulate request data.GET
,POST
, etc.) is easily defined.2. Interface Architecture
Interfaces define the contract that all request classes must follow. This ensures consistency across various request types while allowing flexibility for specialized request structures.
RequestInterface: The base interface that all requests must implement, providing methods for setting headers, fields, query parameters, methods, and more.
RestRequestInterface: Extends
RequestInterface
, offering additional methods specific to RESTful APIs. For example, it includes abuild()
method to finalize the request structure.3. Specialized Request Classes
Specific API endpoints often require specialized request classes. For example,
GetOrderRequest
implementsRestRequestInterface
and provides additional methods likewithExternalReference()
to handle endpoint-specific parameters.By using this pattern, we ensure that each request type adheres to a clear contract while allowing endpoint-specific behavior to be encapsulated in dedicated classes.
Advantages
Modularity and Reusability
Request
class and its associated interfaces provide a highly modular architecture that promotes code reuse. Shared functionality (such as setting headers, methods, and fields) can be centralized in theRequest
class, while individual request types can inherit and extend this functionality as needed.Clear Separation of Concerns
Scalability
Encapsulation
Arr
ensures that the internal structure of the request (e.g., arrays of headers, body fields, and query parameters) remains encapsulated, protecting the integrity of the request data.How It Works
Basic Request Example
Here's a simple example of how to use the new request mechanism to create a GET request:
In this example, the request is constructed by setting the HTTP method, URI, query parameters, and headers. The request can then be passed to an HTTP client for execution.
Specialized Request Example
A specialized request, such as fetching an order by external reference, can extend the base
Request
class and implementRestRequestInterface
.In this example, a method is provided to set an external reference, and the request can be built with the
build()
method, allowing for API-specific logic to be encapsulated.Next Steps
For now, the focus is on laying the foundational framework for a reliable and flexible request mechanism. In future iterations, we can explore additional features like caching, error handling, middleware support, and asynchrony, which would further enhance the overall functionality.
The proposed request mechanism will be reviewed and tested in the upcoming sprint, and feedback will be gathered to assess its performance and usability in various use cases.
Summary
The New Request Mechanism provides a streamlined, modular, and scalable way to handle HTTP requests. Its design supports ease of use while allowing for future enhancements and specialization. We anticipate that this will significantly improve the development process for API integrations and bring a consistent structure to request handling across the system.
This mechanism serves as a solid foundation that we can build upon as we add more advanced features in future versions.
Beta Was this translation helpful? Give feedback.
All reactions