Spring framework and java servlet accept query string parameters in the post request. How can we accept parameter only in form data while making the REST API with POST method?
Related
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
I'm using the proxy integration with my Java lambda function. The input for the lambda handler is a JSON object that represents an incoming request. It has a body, headers, query params and so on. But it doesn't include the source URL that is parsed by the API Gateway for the body, query params and etc. Is there a way to get it?
The thing is API Gateway doesn't support arrays in query parameters. Example: /endpoint?numbers=1&numbers=2. Seems, the only way to pass an array is to pass it as a JSON array string /endpoint?numbers=[1,2] but it is not always suitable. So I want to parse the URL by myself.
Unfortunately, API Gateway doesn't provide you with the full URL for you to parse yourself.
If you have the option of using the POST method to /endpoint, you might consider sending a request body instead of query string parameters.
The 'path' field inside the 'requestContext' field contains the path of API gateway resource. See docs for more details.
you can inject the UriInfo object. It holds all the information you need.
#Context
UriInfo uri;
Im trying to use RequestBodyAdvice in Spring Boot application to validate my JWT token and Device info. It works for POST method as it has #RequestBody in Controller however it is not working for GET method because there is no request body/payload. How to validate GET Services using RequestBodyAdvice, is there any other option?
As far as I know, GET request do not have request body. You should use interceptor or filter.
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.
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