Extend HTTPRequest to support path overrides #288
Merged
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.
This PR extends the existing
HTTPRequest
to take an optional path to support POST requests to endpoints other than/query/1
.Description
We'll need to support requests to Fauna APIs beyond
/query/1
. Today, this API path is hardcoded in both the fetch and http2 client wrappers. This PR does the following:HTTPRequest
to accept an optionalpath
FetchClient
to use default API paths, but override per request when one is provided onHTTPRequest
NodeHTTP2Client
to use default API paths, but override per request when one is provided onHTTPRequest
FaunaAPI
to represent the supported API paths in the driverHTTPRequest["path"]
to the union of supported endpoints viaFaunaAPI
Motivation and context
We need to support more endpoints in this driver. The current http clients really only have a fixed concept of requesting queries or streaming. This change allows for a backwards compatible way to introduce providing a path without breaking existing code or interfaces.
Alternatives considered:
HTTPClient.request
be(path: SupportedFaunaAPIs, req: HTTPRequest)
: backwards incompatpath
to a second optional argument of a newHTTPRequestOptions
interface torequest
: Best alternative, but also lacking much more substance--especially sinceHTTPRequest
already supports additional meta options, like timeout.In the future, we may want to reconsider redesigning these interfaces in a major version bump, but that is out of scope for this PR.
Definitely open the other implementation approaches!
How was the change tested?
These changes have dedicated unit tests. The unit tests validate the override logic as well as type enforcement.
Because these changes are backwards compatible, all existing code and tests should work as expected.
Screenshots (if appropriate):
N/A
Change types
Checklist:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.