2

Here is my spring controller code..

@RequestMapping(value= "/save_item",
method = RequestMethod.POST,produces="application/json")

public @ResponseBody ModelMap saveItem(ModelMap model,
@RequestParam("id") String itemId,
@RequestParam("name") String itemName) {

model.addAttribute("itemId",itemId);
return model;
}

How can i make a rest client using spring rest tempalte?.

I need to send two parameters from my rest client(id,name). Anyone Please help me.

Thanks.

5
  • possible duplicate of RestTemplate post for entity
    – nobeh
    Commented Nov 5, 2013 at 10:10
  • in that example they only send a request using restTemplate.postForObject.i also need to specify accept header in my request.how can i possible that
    – rplg
    Commented Nov 5, 2013 at 11:30
  • refer to this question for post with accept headers stackoverflow.com/questions/19238715/….
    – coder
    Commented Nov 5, 2013 at 12:25
  • it does not wok for me..can u give an example for it?
    – rplg
    Commented Nov 5, 2013 at 12:33
  • Anyone please tell me how can i do this?
    – rplg
    Commented Nov 13, 2013 at 6:30

1 Answer 1

0

You can create a RestTemplate object and execute as this

ResponseEntity<List<City>> result = restTemplate.exchange(
                new StringBuilder(URL).append(city).toString(),
                HttpMethod.GET, null, responseType);

In this project you can find a maven project with spring-boot and sptring-web that uses this restTemplate snippet and jackson for the json response

https://github.com/voliveirajr/dev-test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.