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

Feature Request - support parsing of request.path #128

Open
briantist opened this issue Nov 24, 2021 · 1 comment
Open

Feature Request - support parsing of request.path #128

briantist opened this issue Nov 24, 2021 · 1 comment

Comments

@briantist
Copy link

briantist commented Nov 24, 2021

Unlike the body for example, we can't do intensive parsing of the path. The .regex() and .concat() methods don't work on the path.

The :value part of the path also cannot be limited to specific values, so you can't simultaneously get a particular part of path while limiting which values match.

As an example, I have a config like this:

request:
  method: POST|PUT
  path: "/api/v1/method/create*/resource"

I want to match create*, so create or create-thing or create-other would be valid for that part of the path.

In the response, I want to reference that component, or part of it. I'd like to use regex maybe:

response:
  statusCode: 200
  headers:
    Content-Type:
      - application/json
  body: 'A request to create {{request.path.regex(/create-([^/]*)/)}} has been received.'

However that doesn't work.

If I instead do:

request:
  method: POST|PUT
  path: "/api/v1/method/:method/resource"

then I guess I can do:

response:
  statusCode: 200
  headers:
    Content-Type:
      - application/json
  body: 'A request to {{request.path.method}} has been received.'

Which is something.. but not quite the same, as I can't do any string manipulation on it.

But even worse, is that the config will match paths I don't want it to match, like /api/v1/method/delete/resource.

It seems that my only option is hardcoding the possible permutations of paths I want to match into multiple configs, with a lot of duplication and slightly different responses. The data I need isn't in the body of the request, so it seems like I'm stuck.

@jdietrich-tc
Copy link
Contributor

One of my latest PRs #167 addresses this by adding a new pathVariables object to the request:

So for your case you could have:

request:
 method: POST|PUT
 path: "/api/v1/method/:create/resource"
 pathVariables:
   create: "^create.*"
response:
 statusCode: 200
 headers:
   Content-Type:
     - application/json
 body: 'A request to {{request.path.create}} has been received.'
  • /api/v1/method/create-thing/resource
    • matches
  • /api/v1/method/delete/resource
    • does not match
  • /api/v1/method/delete-create/resource
    • does not match

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