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

Proposal: automatically infer @path #201

Open
gabro opened this issue Mar 15, 2020 · 0 comments
Open

Proposal: automatically infer @path #201

gabro opened this issue Mar 15, 2020 · 0 comments

Comments

@gabro
Copy link
Member

gabro commented Mar 15, 2020

The most common pattern we have in our wiro/tapiro based applications is:

@path("resource")
trait ResourceController[F[_], T] {
  @query
  def example(): F[Example]
}

which will produce this endpoint:

GET /resource/example

Omitting @path will instead result in

GET /ResourceController/example

which is virtually never what we want.

I propose we optimize for the most common use case by automatically inferring path from the controller name using a regex like ^(\w+)Controller$.

Under this scheme one would be able to omit path

trait ResourceController {
  @query
  def example(): F[Example]
}

and have an endpoint

GET /resource/example

Using @path is still supported if one needs a custom prefix


To summarize, the strategy to generate a the path prefix would be (in order of descending priority)

  • respect @path if provided
  • try inferring from the controller name (we could make this configurable if we have projects that use a different scheme than ^(\w+)Controller$)
  • fall-back to the controller name if everything else fails (I would log a warning in this case, since I think it will never happen on purpose)

What do you think @calippo?

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

No branches or pull requests

1 participant