0

I am trying to achieve this

enter image description here

Which is /delete/{id}

How do I do this in java?

String id = "123";
OkHttpClient client = new OkHttpClient();
RequestBody form = new FormBody.Builder()
        .add("id", id)
        .build();

Request request = new Request.Builder()
           .url("http://localhost:3002/delete/")
           .put(form)
           .build();
        client.newCall(request).execute();

Doesn't work. How do I add url parameters with this?

bobby
  • 183
  • 1
  • 1
  • 8

1 Answers1

0

Append the id to the url function argument like url("http://localhost:3002/delete/"+id). You have a request query parameter and you are not appending it to the URL.
Also, put(form) sets the request body and not the query parameter.

You can check out the difference between PUT and POST and this post for more explanation

Shankha057
  • 1,072
  • 14
  • 30