-
Notifications
You must be signed in to change notification settings - Fork 903
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
apiv2 #2762
apiv2 #2762
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think creating a parallel package is a great idea (allows us to migrate gradually without worrying about getting it 100% right all at once). But if we're gonna do that, feels like we can kinda just go nuts on the new implementation and make the interface exactly what we want without worrying about backwards compat. For instance, maybe we should take an instantiated client approach, something like:
import { Client, hostingOrigin } from "../apiv2";
const api = new Client({
origin: hostingOrigin,
apiVersion: "v1beta1",
auth: true
});
const channel = await api.post<CreateChannelRequest, Channel>({
ttl: `${ttlMillis / 1000}s`
});
that's just an example, but we could try to build a more opinionated client experience and maybe pull in some OP-specific utilities (for instance, imagine a listPaginated()
method that auto-paginates using OP parlance).
I'm not opposed to a "the existing thing, but TypeScript", but it looks like this approach is changing a fair amount of the surface but not really as a ground-up reimagining.
Another example here is that we no longer really need to vary requests by scope -- that's not a thing we do anymore since we rely on IAM to be our permissions gate.
this.opts.auth = true; | ||
} | ||
if (this.opts.urlPrefix.endsWith("/")) { | ||
this.opts.urlPrefix = this.opts.urlPrefix.substring(0, this.opts.urlPrefix.length - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't substr
preferred now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I recall. They're two different functions (which can be basically substituted here): the second argument for substr is the number is the length to return, the second argument to substring is the index to stop at. Using 0 for the first argument, either is technically fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please manually test codepaths for all swapped implementations before merging.
Description
Creating a new
apiv2
package that's in typescript and will allow us to change out the currentapi
package (based onrequest
). This is built usingnode-fetch
which is fairly light-weight.The exported
Client
module has a genericrequest
method for... generic requesting, but also has 'verb' methods matching various HTTP verbs to make most requests very simple to write.Scenarios Tested
I've kept this to the
hosting:channel:*
commands and have been using them as my tests. Seems to be working quite well!hosting:channel:list
workshosting:channel:create
works (and with--expires
)hosting:channel:deploy
workshosting:channel:delete
works