Skip to content
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

API routers and config transformation #41129

Open
cpuguy83 opened this issue Jun 19, 2020 · 2 comments
Open

API routers and config transformation #41129

cpuguy83 opened this issue Jun 19, 2020 · 2 comments
Assignees
Labels

Comments

@cpuguy83
Copy link
Member

Currently API routers are responsible for transforming requests based upon API version, however this has lead to host specific details leaking into the http router.
We also don't really want API version specific details leaking into the implementation.

I propose that we add a shim here so that transformations can be made after the request is routed.
This could look something like:

// the API router
func(r *fooRouter) createFoo(ctx context.Context, w http.Response, req *http.Request) {
  // make a fooConfig from the reuqest
  r.backend.Create(ctx, fooConfig)
}
func(b *fooBackend) Create(ctx context.Context, fooConfig Config) {
    b.transform.Create(ctx, &fooConfig)
}
func(t *fooTransformer) Create(ctx context.Context, fooConfig) {
  ver := getApiVersion(ctx)
  if ver.LessThan("1.2") {
      // set some value
  }
}

Then the transformer can be configured with host specific details rather than relying on the HTTP router to have these details.
It also seems like it makes it easier to unit test such transformations.

@thaJeztah thaJeztah changed the title API routers and config transormation API routers and config transformation Jun 22, 2020
@thaJeztah
Copy link
Member

Trying to understand the impact/proposal (so bear with me)

Where would that transform package live? Isn't API version (and what it supports) part of the API layer?

I propose that we add a shim here so that transformations can be made after the request is routed.

Some things need to be handled before the request is performed by the backend (i.e., it's not just output but also input that needs to be changed?)

@cpuguy83
Copy link
Member Author

Where would that transform package live? Isn't API version (and what it supports) part of the API layer?

It is, but it doesn't need to be within the router.
I think we've mixed the HTTP interface (router) with the implementation of the API.

Some things need to be handled before the request is performed by the backend

Yes, that's pretty much the idea here.
Really I was not even considering output, which we also have some stuff mixed in with the engine implementation rather than in some API layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants