How to use a Spring Boot API in a java method

Hisham Bawa :

I'm new to programming and I got a project to make a rest API. I made one using spring boot to use GET and POST operations. Now I'm trying to get it to work on a simple java application where,

  • The user inserts their first name using the java scanner.
  • Then sends a POST request to send it to a database.

So far the API works fine in Postman but I have no idea on how to add it to java using a method.

( I used this tutorial to make the api : https://www.callicoder.com/spring-boot-rest-api-tutorial-with-mysql-jpa-hibernate/ )

Sri :

Good you are learning.. keep it up.. Soultion for your question is

You have to implement one RestClient using RestTemplate of Spring or other ( How do you create a REST client for Java? )

Say you have your endpoint http://localhost:8081/api/name

enter image description here

You have to create RestClient like this ( I have used simple one just for example purpose )

enter image description here

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=373606&siteId=1