{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
5
Question by Nagashree B · May 21, 2015 at 07:37 AM · 5.8k Views api proxyconditional flow

how to match regardless whether there is a trailing '/' on the url when you define a resource in api proxy

I have an issue while defining a resource in my api proxy.

I want to allow only POST requests if the path suffix is /applicationDetails or /applicationDetails/

Sometimes users hit the url as /applicationDetails/, it doesnt go through the conditional flow in this case, although i would want it to go through

I tried defining as /applicationDetails* it had no effect.

I got through a workaround by manually changing the condition as

<Condition>(proxy.pathsuffix MatchesPath "/applicationDetails") or (proxy.pathsuffix MatchesPath "/applicationDetails/") and (request.verb = "POST")</Condition>

Is this the best way?

Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

2 Answers

  • Sort: 
avatar image
8
Best Answer

Answer by Anil Sagar @ Google   · May 21, 2015 at 09:01 AM

Dear @Nagashree B ,

Apigee conditions supports regular expressions JavaRegex , you can use below one too. For more details refer Condition Reference Doc here.

<Condition>(proxy.pathsuffix JavaRegex "/applicationDetails(/?)") and (request.verb = "POST")</Condition>

If you would like to match against path only then you can extract path segment into a variable and compare against that variable in above conditional flow. For more information look at Extract Variable Policy specifying patterns with multiple variables.

Cheers,

Anil Sagar

Comment
Add comment Show 3 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dino ♦♦   · May 21, 2015 at 05:31 PM 4
Link

To answert the question - "is this the best way?" My answer is "maybe". It's perfectly readable and it works, so why not use it? Regex (aka regular expression matching) is another option and is perhaps more flexible.

If using regex, then I suggest that you include the string terminator in the pattern. This will let you match only when the pathsuffix is /applicationDetails or /applicationDetails/ but not /applicationDetails/something .

The suggested regex ( "/applicationDetails(/?)" ) will allow a slash, or maybe not, followed by anything at all. It will match even /applicationDetailsAreLovely .

A more restrictive regex with the terminator is "/applicationDetails(/?)$" . This would prevent matches on /applicationDetails/something and /applicationDetailsAreLovely

avatar image KirillAgeev Dino ♦♦   · Mar 12, 2018 at 03:46 PM 1
Link

Actually /? means zero or one slash and it won't allow /something at the end, no need to add EOL.

avatar image jonesfloyd ♦♦ · May 22, 2015 at 09:26 PM 0
Link

Great thread, all. Thanks for asking, Nagashree. FYI that I've added a link to this from the docs, in both the Conditions reference and API resources and conditional flows topics.

avatar image
2

Answer by tpearson · Jan 28, 2016 at 05:24 PM

The regex is a great feature but for your case this might be a simpler solution

<Condition>(proxy.pathsuffix ~~ "/applicationDetails(/?)") and (request.verb = "POST")</Condition>

-- Doh - just realized that this is exactly the same solution - the ~~ being shorthand for JavaRegex!

Comment
Add comment Show 2 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Abiram Radhakrishnan · Aug 11, 2019 at 03:12 PM 0
Link

Based on REST best practices

Open API Specification with required Docs should clear the user about usage of /applicationDetails instead of /applicationDetails/

Does /applicationDetails and /applicationDetails/ represent different resource ?

from REST perspective. Its more of educating the user, is that correct approach ?

Reason : /applicationDetails will result in collection Vs /applicationDetails/ used only when representing specific details

avatar image Dino-at-Google ♦♦ Abiram Radhakrishnan   · Aug 13, 2019 at 04:55 PM 0
Link

It's probably bad form to allow request URLs with a trailing slash. It's bad aesthetics in my opinion. But some people have clients that append the trailing slash. As described above, You can handle it with a regex match in the Apigee Edge flow condition.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using arithmetic operators in conditions 1 Answer

OptinalTargetURL does not add route rule in new version of proxy editor. 1 Answer

Routing Target Endpoint of API proxy as No Target 1 Answer

Please suggest me how to get rid of extra characters that are getting generated when i create a API proxy for a service with query parameters.Thanks in Advance. 1 Answer

How to set isHTTPStatusTooManyRequestEnabled to return 429 http response 12 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges