-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: get
on hyper services should return the "hyper response" shape, not the resource.
#531
Comments
No matter what, this is a breaking change for consumers, which stinks. Idk how to get around that. |
Making it return a hyper response if fine with me, maybe the hyper sdk can help with the breaking change |
Maybe adding an option to each of the This means folks will need to update their |
I like the approach I laid out in my last comment: Add support for a I'll need to add a migration guide in the docs for consuming via REST and via Eventually, we can default |
Yep
Sounds great!
…Sent from my iPhone
On Nov 4, 2022, at 5:30 PM, Tyler Hall ***@***.***> wrote:
I like the approach I laid out in my last comment:
Add support for a x-hyper-legacy-get header on hyper-app-opine for get endpoints. Default it to enabled or 1. That will be be used to instruct core to follow legacy behavior and return the resource itself, or to return a hyper response for get calls. Then push a breaking change on hyper-connect that sets x-hyper-legacy-get to disabled or 0.
I'll need to add a migration guide in the docs for consuming via REST and via hyper-connect.
Eventually, we can default x-hyper-legacy-get to 0 on hyper-app-opine as a breaking change.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.
|
…531 This will allow consumers who would like to use the legacy format to forcibly continue doing so, even after the default in hyper is set to the new API
…531 This will allow consumers who would like to use the legacy format to forcibly continue doing so, even after the default in hyper is set to the new API
I need to update docs at doc.hyper.io with directions on how to use I'll create separate issues to:
|
|
See #546 I'll have to update the ports to the new shape along with the adapters, in tandem, which I suppose is the point, when we decide to make the swap over the new shape as the default. |
We've had internal conversations about this, but I would like to track this as it's increasingly becoming a point of friction with hyper developers.
Background
Almost all hyper service apis return a common shape, I'll refer to as a "hyper response shape". This looks like:
If
ok
isfalse
,msg
andstatus
may be provided for additional context. For example, if a document isn't found,getDocument
will return a404
status
.Otherwise, if
ok === true
, service api responses will include a field on the "hyper response" ie.data.queryDocuments
andcache.listDocs
will have adocs
field andsearch.query
will have amatches
field. Effectivelyok
is discriminator field.Similar to
fetch
,hyper-connect
, our hyper REST client, will only throw if a5xx
status code is received from a request to a hyper REST api. So4xx
must be handled by consumer code, which is by design. A common pattern is something like:Since
ok
is a discriminator, this works great with TypeScript, as TS is smart enough to inform Intellisense which fields are available onres
based on the value ofok
.Problem
The exception to this is the
get
apis fordata
andcache
. When fetching a single resource, hyper service apis will return the resource if found, and a "hyper response" if not found. This divergence from the common shape results in unergonomic consumer code. For example:Checking
status
has similar issues. What if the resource itself hasstatus
field?On top of this, TS doesn't catch this overlap, making
get
a potential source of esoteric bugs, if a resource happens to have aok
orstatus
field.Basically,
get
must be coded for differently than every other hyper service api, and also may introduce unintended bugs in consumer code.Potential solutions
Make
get
on hyper service adapters return a "hyper response"Instead of the resource,
get
for each service would return a field on a hyper response, ie.data.getDocument
could instead return:This would mean
get
is handled just like any other hyper service response.Pros
Cons
Make the hyper app return a hyper response
We could make the hyper app, ie.
hyper-app-opine
take the response from core and wrap it in a hyper response ie.Pros
Cons
Make hyper core return a hyper response
We could make the hyper core, take the response from the adapter and wrap it in a hyper response ie.
Pros
Cons
The text was updated successfully, but these errors were encountered: