1

I want to send a PATCH Request to another Springboot Application running at localhost:9096 from my Spring boot app. I have to encode certain parameters into the URL to which i have to send the patch request. Here is something that i tried:

final String url="http://localhost:9096/id/{id}/status/completed?reason=success&tag=1234";

    Map<String, String> parametersUri = new HashMap<String, String>();
    parametersUri.put("executions", executionPythonEntity.getExecutionId());

    restTemplate.exchange(url , HttpMethod.PATCH, new HttpEntity<>(parametersUri, headers), String.class, parametersUri);
Jerrin Thomas
  • 269
  • 3
  • 14
  • What have you already tried? Did you check the official Springboot documentation? A quick Google search? Remember: Stack Overflow is not a code writing service. – Mathyn Feb 06 '19 at 14:10
  • https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html – akuma8 Feb 06 '19 at 14:32
  • Welcome to stackoverflow jerrin – Matt Feb 07 '19 at 01:01

1 Answers1

0

You could leverage feign or Resttemplate

Check out this SO questions for Resttemplate

Example of resttemplate:

HttpHeaders requestHeaders = new HttpHeaders();
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();

// Add the String message converter
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());

// Make the HTTP POST request, marshaling the response to a String
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

Check out this SO question for feign

From the docs:

@FeignClient("stores")
public interface StoreClient {
    @RequestMapping(method = RequestMethod.GET, value = "/stores")
    List<Store> getStores();

    @RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
    Store update(@PathVariable("storeId") Long storeId, Store store);
}

Please elaborate on your question if you would like a more elaborate answer.

Also I would like to add that there are a couple other ways to send post requests but I think the 2 I mention should be sufficient for your purposes.

Matt
  • 379
  • 3
  • 9