Home > database >  Java REST api PATCH request
Java REST api PATCH request

Time:05-16

I have to modify java based old project(servlet , Gradle project) which was not integrated with any of Java framework. For a recent project integration requirement, needs to call a external Api' PATCH request and change some value(owner ID) time to time on that external api hosted web application.

Endpoint looks like following https://reverinapi/privivo/api/deys#/v1/drive/maks/{id}

Need to change owner id time to time and JSON should following,

{ "meta": { "ownerId": "smtip|appownid1" } }

I tried following way,

   com.google.gson.JsonObject mainObject=new com.google.gson.JsonObject();
   com.google.gson.JsonObject meta=new com.google.gson.JsonObject();
   meta.addProperty("ownerId", "smtip|appownid1");
   mainObject.add("meta", meta);

I don't familiar with how to call the api endpoint and please let me know if there any other efficient way to do this api call and change the value.

CodePudding user response:

You need to use some HTTP client library to make the request. There are likely many available for Java, but Apache's is one.

Ah, I also just learnt that as of Java 11, there's an HTTP client included: https://www.baeldung.com/java-9-http-client.

  • Related