Announcement Announcement Module
Collapse
No announcement yet.
Optional parameters in rest url Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Optional parameters in rest url

    Hi

    Is it possible to have optional path variables while implementing rest services with spring 3.1.1

    ex.:

    foollowing urls must map to same method:

    http://localhost:8080/location/ind

    http://localhost:8080/location/ind/del

    I use following requestmapping for first url:

    /location/{contry}

    and for second url:

    /location/{contry}/{state}


    Currently i am using differentt methods for both urls

  • #2
    As per the REST spec you should have 2 REST services, which you have already created. But If you really want to have a single service, you can do it in follwoing way.
    • I don't think Spring MVC provide a straight way to do it. But you can use URLRewrite and can create the following rule using rest Controller path /location/{contry}

      Code:
        <rule>
              <from>/location/[a-z]/[a-z]</from>
              <to>/webservice/$1?state=$2</to>
       </rule>
      You can play more with URLRewrite for more flexible URLs.
    • If you are using JAX-RS based framework then edit the @Path with /location/{contry}/{state:.*} and you are done.

    Comment

    Working...
    X