ronypatil
ronypatil

Reputation: 163

passing parameter in webservice API

I am new at webservices and currently able to run my query by calling https://localhost/application/service/v1.0/contacts/account={accountId} I want to make my url look like https://localhost/application/service/v1.0/contacts?account={accountId}

May I know How to achieve this not using QueryParam ? I am working in spring mvc

@Controller 
public class ContactListResponseController extends BaseWebServiceController 
{ 

 public static final String PATH = "/v" + VERSION + "/contacts/account={accountId}"; 

 @Autowired 
 private ContactService contactService; 

 @RequestMapping(value = PATH, method = RequestMethod.GET) 
 @ResponseBody 
 public ContactListResponseBean doGetMyAssignedAccounts (@PathVariable String accountId, 
                                                       HttpServletRequest request, 
                                                       HttpSession session, 
                                                       HttpServletResponse response, 
                                                          @ModelAttribute(User.USER_REQUEST_VAR) User user) 
  throws Exception 
  { 

    List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId); 
    ContactListResponseBean result = new  ContactListResponseBean(contactList); 
    return result; 
  } 

}

Upvotes: 0

Views: 36

Answers (2)

0gam
0gam

Reputation: 1423

This sample.

@RequestMapping("/pets/{petId}")
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
    // implementation omitted
}

Your code.

@Controller 
public class ContactListResponseController extends BaseWebServiceController 
{ 

   public static final String PATH = "/v" + VERSION + "/contacts/{accountId}"; 

   @Autowired 
   private ContactService contactService; 

   @RequestMapping(value = PATH, method = RequestMethod.GET) 
   @ResponseBody 
   public ContactListResponseBean doGetMyAssignedAccounts (@PathVariable String accountId, 
                                                       HttpServletRequest request, 
                                                       HttpSession session, 
                                                       HttpServletResponse response, 
                                                          @ModelAttribute(User.USER_REQUEST_VAR) User user) 
   throws Exception 
   { 

      List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId); 
      ContactListResponseBean result = new  ContactListResponseBean(contactList); 
      return result; 
   } 

}

Ajax url = "/v" + VERSION + "/contacts/" + accountId,

:D

Upvotes: 0

Blank
Blank

Reputation: 12378

It is a simple thing, try this:

@Controller 
public class ContactListResponseController extends BaseWebServiceController 
{ 

 public static final String PATH = "/v" + VERSION + "/contacts"; 

 @Autowired 
 private ContactService contactService; 

 @RequestMapping(value = PATH, method = RequestMethod.GET) 
 @ResponseBody 
 public ContactListResponseBean doGetMyAssignedAccounts (@RequestParam("account") String accountId, 
                                                       HttpServletRequest request, 
                                                       HttpSession session, 
                                                       HttpServletResponse response, 
                                                          @ModelAttribute(User.USER_REQUEST_VAR) User user) 
  throws Exception 
  { 

    List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId); 
    ContactListResponseBean result = new  ContactListResponseBean(contactList); 
    return result; 
  } 

}

Upvotes: 2

Related Questions