1

Hello I am relative new in Java Programming and I'm kinda struggling with the Restful API.

I have a json file which is accessible via an URL-Link.

{ "incident": [
{
  "id": 1,
  "name": "Fire",
  "text": "Fire burns the whole Street, come fast!",
  "longitude": 13.4405,
  "latitude": 52.5244
},
{
  "name": "Traffic",
  "text": "Have\n",
  "longitude": 13.4804,
  "latitude": 52.8632,
  "id": 2
}]}

In my Code I have sucessfully implemented a read and post Function and i know that the http request for delete look like this:

            URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection)
                url.openConnection();
        //Step 2: define the request
        conn.setRequestMethod("DELETE");
        conn.setRequestProperty("Content-Type","application/json");
        conn.setRequestProperty("Accept","application/json");
        conn.setDoOutput(true);
        conn.setDoInput(true);

        JSONObject jsonObject = new JSONObject();


        DataOutputStream os = new DataOutputStream(conn.getOutputStream());
        os.writeBytes(jsonObject.toString());
        status = conn.getResponseCode() + ": " + conn.getResponseMessage();

        os.flush();
        os.close();

I want to remove the data with "id=2" but how I can do this?

0 Answers0