Postman passed values get into servlet - java

I am passing some values (like firstname, lastname, email, phone) from postman doPost request(as JSON) at Url like below to java TestServlet
https://xx.xxx.xxx.xxxx:yyyy/xyz/TestServlet
I like to retrieve these values in servlet and save to topic on kafka producer.
How to retrieve postman passed values inside servlet and later store to producer

Postman is an implementation detail. You could use any HTTP client to send a request to the servlet.
Inside your doPost method body, you'd parse the request body content as JSON, then you'd construct (or reference) a KafkaProducer instance, then build a new ProducerRecord, and send it

Related

How can I use a post request with Retrofit to deliver data in parameters?

I designed an API that sends data in parameters, however retrofit prevents us from sending data in parameters through a post request. Is there a way to send data in parameters through a post request with retrofit?
Reference:
https://square.github.io/retrofit/2.x/retrofit/retrofit2/http/Field.html
#FormUrlEncoded
#POST("/")
Call<ResponseBody> example(
#Field("name") String name,
#Field("occupation") String occupation);
You can make a Pojo/Data class for your desired parameters and Then you can make an object by passing all your parameter. Then you can send data through post by using #Body tag like:
#POST("/")
Call<ResponseType> send(#Body Data data)

How to get the request and response information and send them as a post request in Jersey?

For example, when a user calls GET /API1/employee to get all the information about the employees in the database. I want to create a class and implement serval methods to get the request and response information like userid, timestamp when the api is called. And then send the JSON data to another api as a post request? Any reference or example about it?

Spring boot - WeatherApp - API

Im trying to make weather apps with spring boot MVC. I wanted to use api from: openweather.com.
In the controller I have a method to pass the parameter. I have two html pages. One with form and submit, the other to display the string of the form.
How to bind an API with my parameter from a form and how to retrieve JSON information.
#GetMapping("/show")
public String show(#RequestParam ("city") String city, ModelMap modelMap){
modelMap.addAttribute("city", city);
return "article/show";
}
You should have a get listener in your back-end code that will get the weather from openweather. It should look something like this:
#RequestMapping("/weather")
public String show(#RequestParam ("city") String city)
//Method body
//In the method body you should make a request to the openweather server with an api key which you can get by registering in the website. You can achieve this with Unirest library (it's the easiest way)
HttpResponse<JsonNode> response = Unirest.get("http://api.openweathermap.org/data/2.5/weather")/
.queryString("APPID","YOUR_APP_ID")
.queryString("city",city)
.header("content-type","application/json")
.asJson();
This method will return a JSON with all the data you need, which you can parse with RestTemplate.
You can use RestTemplate to retrieve JSON from weather API.
You have an example on link below:
http://www.baeldung.com/rest-template
After you receive the JSON object then you can add it to the model and send it to JSP or some other templating engine.

Can I access request parameters in a custom Google Cloud Endpoints Authenticator?

Is there a way to get access to the request parameters in a custom com.google.api.server.spi.config.Autenticator?
I would like to authenticate my users using a token, sent as a request parameter according to https://<mydomain>/_ah/api/v1/myapi/endpoint?token=<mytoken>. Unfortunately, in this case, it is not possible to send it as a request header. Currently, I manage authentication in each endpoint (where I do have access to the request parameters, either through the HttpServletRequest object or through a named parameter) but it would be nice to decouple auth from implementation.
As I understand, Cloud Endpoints will wrap the original request in a new POST request to /_ah/spi/... but only the request headers will be accessible in the Authenticator.
It doesn't matter if the initial request to Cloud Endpoints is GET or POST.
Your understanding is correct--your request is translated such that all query parameters are injected as part of the JSON body as well. I believe the body does have the query parameter, but I'm not 100% sure on that. If you upgrade to the new Endpoints Frameworks beta, you can access it using getParameter or getParameterValues on the servlet request, as you would expect.

For a #GET operation which one to use #QueryParam or #FormParam

I am developing a server side application (not client). I have a list operation where I am using #GET and I am passing the parameters as #QueryParam. Should I use #FormParam? Will it be helpful while developing the client?
The #FormParam annotation will expect the parameter to be in the body of the request as sent by an HTML form submit.
An HTTP GET should not use a request body. So, keep using #QueryParam for #GET.
See also:
HTTP GET with request body

Categories