'Java REST api PATCH request

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1