Skip to content

Instantly share code, notes, and snippets.

@edjeordjian
Created September 4, 2021 00:47
Show Gist options
  • Save edjeordjian/efd2eb32c166ba0f3ae6e41792d48da0 to your computer and use it in GitHub Desktop.
Save edjeordjian/efd2eb32c166ba0f3ae6e41792d48da0 to your computer and use it in GitHub Desktop.
Quick way to send a post message in Spring Boot.
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
public class SimplePostRequestInSpringBoot {
public void simplePost() {
RestTemplate client = new RestTemplate();
client.getMessageConverters().add(new StringHttpMessageConverter());
String url = "http://localhost:8080/your/endpoint/here";
client.postForObject(url, new YourDTO(), YourDTO.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment