Results 1 to 2 of 2

Thread: Optional parameters in rest url

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    3

    Post 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. #2

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •