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

request help: how to use wildcards in paths with ApisixRoute CRD #1927

Closed
machadojoao opened this issue Aug 16, 2023 · 7 comments · Fixed by #2140
Closed

request help: how to use wildcards in paths with ApisixRoute CRD #1927

machadojoao opened this issue Aug 16, 2023 · 7 comments · Fixed by #2140
Assignees
Labels
enhancement New feature or request

Comments

@machadojoao
Copy link

Issue description

Hi, I have some APIs paths like:

/api/:id/my-entity1
/api/:id/my-entity2

I could not use the CRD ApisixRoute because it has a validation for this field that the wildcard must be at the end.

spec.http[0].match.paths[0] in body should match '^/[a-zA-Z0-9\-._~%!$&'()+,;=:@/]*\*?$'

But if I use the admin api directly (our by the dashboard), I'm able to use a wildcard at path like:

{ "uris": [ "/api/*/my-entity1", "/api/*/my-entity2" ], "name": "route, "priority": 0, "methods": [ "GET" ], "upstream_id": "2fa86803" "status": 1 }

Is there anyway to do this with CRDs?

Environment

  • your apisix-ingress-controller version (output of apisix-ingress-controller version --long):
  • your Kubernetes cluster version (output of kubectl version):
  • if you run apisix-ingress-controller in Bare-metal environment, also show your OS version (uname -a):
@tao12345666333 tao12345666333 added the enhancement New feature or request label Aug 24, 2023
@tao12345666333
Copy link
Member

Good catch!

I think we can change the rules.

@xtha
Copy link

xtha commented Nov 13, 2023

The ApisixRoute "ar-iot-node" is invalid: spec.http.match.paths: Invalid value: "/assets/help/*/rulenode/*": spec.http.match.paths in body should match '^/[a-zA-Z0-9\-._~%!$&'()+,;=:@/]*\*?$'

@byblakeorriver
Copy link

I hit the same issue.

@pottekkat
Copy link
Contributor

As a workaround, you can use regular expression matching. For example:

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: speaker-topics-route
spec:
  http:
    - name: speaker-topics
      match:
        hosts:
          - conferenceapi.azurewebsites.net
        paths:
          - /*
        exprs:
          - subject:
              scope: Path
              name: topics
            op: RegexMatch
            value: "^/speaker/[^/]*/topics$"
        methods:
          - "GET"
      upstreams:
        - name: conference-api-upstream

See navendu.me/posts/batching-requests for full explanation.

Should we still change the rule or continue with this workaround?

@byblakeorriver
Copy link

This workaround works if there is only one ApiSixRoute with http[0].match.paths = /*
If you have two paths like that the second one will never be reached.

@mkyc
Copy link

mkyc commented Jul 17, 2024

FYI @byblakeorriver I just tested it using apisix helm chart version 1.4.0 which is 3.3.0 application version and it worked for me.

@byblakeorriver
Copy link

Thank you! It looks like it is working for me now too!

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

Successfully merging a pull request may close this issue.

7 participants