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

.forMethod() and .forPath() new matchers proposition #81

Open
OnkelTem opened this issue May 12, 2022 · 2 comments
Open

.forMethod() and .forPath() new matchers proposition #81

OnkelTem opened this issue May 12, 2022 · 2 comments

Comments

@OnkelTem
Copy link

OnkelTem commented May 12, 2022

Currently if you need to match an URL, you have to use one of the method-specific matchers: forGet(), forPost(), etc. But when you need to match a URL for some of the HTTP methods, you have to repeat yourself:

server.forGet(url)//...;
server.forPost(url)//...;
server.forOptions(url)//...;
server.forHead(url)//...;
// etc

I propose to add 2 new methods:

  • forMethod(method) matcher, which is true when method matches the current method
enum HttpMethods {
  CONNECT = 'CONNECT',
  DELETE = 'DELETE',
  GET = 'GET',
  HEAD = 'HEAD',
  OPTIONS = 'OPTIONS',
  PATCH = 'PATCH',
  POST = 'POST',
  PUT = 'PUT',
  TRACE = 'TRACE',
}

forMethod(method: HttpMethods): RequestRuleBuilder
  • forPath(path) - matcher which is true when path matches the current requested path.
forPath(path: string | RegExp): this;
@OnkelTem OnkelTem changed the title .forMethod() and .forPath() proposition .forMethod() and .forPath() new matchers proposition May 12, 2022
@pimterry
Copy link
Member

Sure! PRs welcome. This should be very quick & easy since the matchers already exist for internal use (defined here and here), it's just that it's not exposed in the rule builder API.

@OnkelTem
Copy link
Author

Yep!

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

No branches or pull requests

2 participants