0

There is an API which sends back data on get request from a database. The database is huge, so the data we need, we have to specify it in json. So actually we have to send a json with get request to get back the desired data.

It has been implemented in python requests.get(url, headers, json) I want to do this in Java/Spring.

I tried webclient but it did not work.

Asim
  • 51
  • 7
  • Hi i suggest you start with the Spring Webflux spring tutorial - https://spring.io/guides/gs/reactive-rest-service/ , after that the Spring JPA tutorial https://spring.io/guides/gs/accessing-data-jpa/ , this should give you some insight on how to wire things up. – Kevvvvyp Mar 23 '21 at 15:02
  • Yeah thanks @Kevvvvyp I have gone through the basic, but it has not solved the problem. is it possible to send a json or payload/body in the get request in java? i did that in python – Asim Mar 23 '21 at 15:18
  • Typically GET requests don't contain a body which is probably why you don't see an expliclt method for it on Webclient.get() https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/reactive/function/client/WebClient.RequestHeadersUriSpec.html But you could make use of webclient.method passing HttpMethod.GET as a parameter, see https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/reactive/function/client/WebClient.RequestBodyUriSpec.html – Kevvvvyp Mar 23 '21 at 15:22
  • It helped, thanks mate! – Asim Mar 23 '21 at 15:48

1 Answers1

0

To supply a body as part of a GET request using WebClient you would need to use webclient.method(HttpMethod.GET)

Kevvvvyp
  • 1,704
  • 2
  • 18
  • 38