refactor(headless-future): add api facades and contributors#7617
Open
fbeaudoincoveo wants to merge 13 commits into
Open
refactor(headless-future): add api facades and contributors#7617fbeaudoincoveo wants to merge 13 commits into
fbeaudoincoveo wants to merge 13 commits into
Conversation
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
@coveo/atomic
@coveo/atomic-hosted-page
@coveo/atomic-legacy
@coveo/atomic-react
@coveo/auth
@coveo/bueno
@coveo/create-atomic
@coveo/create-atomic-component
@coveo/create-atomic-component-project
@coveo/create-atomic-result-component
@coveo/create-atomic-rollup-plugin
@coveo/headless
@coveo/headless-react
@coveo/shopify
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces the concepts of API endpoint clients, facades, request contributors, and response handlers.
Proposal
Clients
API endpoint clients are defined under
api/interface/<endpoint>-endpoint/<endpoint>-endpoint-client.ts(e.g.,api/interface/search-endpoint/search-endpoint-client.ts)A client is entirely unaware of the
coreandpubliclayers. It defines and exports its own types, which are tied to the underlying Coveo API specification.It receives its request body and configuration from its caller (which outside of unit tests is going to be the corresponding API endpoint facade). Its reponsibility is straightforward: execute the request and return the response. It does not transform the requests or the responses, but merely transports them.
Facades
API endpoint facades are defined under
core/interface/api/<endpoint>-endpoint/<endpoint>-endpoint-facade.ts(e.g.,core/interface/api/search-endpoint/search-endpoint-facade.ts).A facade is aware of the
apilayer, and is responsible for:Facades are used by feature actions and controllers to call endpoints.
Contributors and Handlers (Middlewares)
Request contributors and response handlers (i.e., middlewares) are defined in
core/interface/<feature>/<feature>-loader(e.g.,core/interface/search-box/search-box-loader.ts).Rather than having a single centralized request builder per endpoint with lots of complex logic, features individually "contribute" to various endpoint request bodies by registering request middlewares.
For instance, the query feature might contribute to search-endpoint request bodies by registering a middleware that sets the
qproperty of the request to the value ofqueryin its slice.Facades then simply assemble the full request body from their registered middlewares, without applying any further logic.
A similar principle applies to response: each feature that should modify its state when a given endpoint response comes in registers its own response middleware. The response object itself is readonly, and the feature may only modify its own state.
The proposal here is to register request and response middlewares in the "loader" function of each feature, so that we don't have to repeat the same middleware logic in controllers and actions. The loader ensures that the correct feature slice is loaded, and registers all request / response middlewares on the necessary facades.