Q:

How to pass post json Object Data to an api using java/Spring/rest

Problem Statement
I am new to Spring/Rest Applications and I have data in an Object.
Now,I need to pass this data to an API.
Below is the sample curl Attached for a single record- 
curl --request POST \
  --url http://eventapi-dev.wynk.in/tv/events/v1/event \
  --header 'cache-control: no-cache' \
  --header 'content-type: application/json' \
  --header 'postman-token: 67f73c14-791f-62fe-2b5a-179ba04f67ba' \
  --data '{"name":"hotel california", "createdAt":1505727060471, "steamUrl":"https://www.youtube.com/watch?v=lHje9w7Ev4U"}'

The response I got after Hitting curl url in Terminal is Ok

Can I anyone guide me how to write the Code in Java.

A:

You can using okhttp (https://github.com/square/okhttp) to call this api.
Example:
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n\t\"name\":\"hotel california\", \n\t\"createdAt\":1505727060471, \n\t\"steamUrl\":\"https://www.youtube.com/watch?v=lHje9w7Ev4U\"\n}");
Request request = new Request.Builder()
  .url("http://eventapi-dev.wynk.in/tv/events/v1/event")
  .post(body)
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .addHeader("postman-token", "08af0720-79cc-ff3d-2a7d-f208202e5ec0")
  .build();

Response response = client.newCall(request).execute();

