I am trying to read the request body data from ServerWebExchange in Spring Cloud Gateway. can anyone please help me how to do this.
Also why this simple task is so difficult in reactive programming.
It's the same as reading or modifying the response body.
see: ModifyRequestBodyGatewayFilterFactory and ModifyResponseBodyGatewayFilterFactory
How to get response body in Spring Gateway
Related
I have built an AWS API Gateway Rest API integration with AWS SNS.
(Setup in simplified form)
Post Requests --> RestAPI in AWS API Gateway -->SNS
I want to configure the Gateway to respond to the post request with one field I get from PostRequestsBody.
But in the docs that I have read, I am able to send just the response body of the SNS request.
1>Is it possible to respond with body PostRequest as a response body in Gateway?
2> if yes please direct me to the docs or please explain how it can be achieved.
I have gone through http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
which had explained just how to respond with details of integrated service(SNS in this case) response.
Even though this question is old now, it appears in search results.
AWS doesn't directly have a way to do this, but people have found hacks such as https://stackoverflow.com/a/61482410/563812
I am using spring cloud gateway Hoxton.M1 release to implement an API gateway. I have the following two spring boot apps -
Client <-> Router App <-> Wrapper App <-> Downstream application
Router App - This application has spring cloud gateway. All routes in application.yml point to a common REST controller end point in Wrapper application by passing a request header attribute "apiendpointid" to diff b/w diff api calls. Below is a sample route entry
- id: milestone
uri: http://localhost:5001
predicates:
- Path=/track/milestone
- Method=POST
filters:
- RewritePath=/track/milestone,/gateway/api/internal/process
- AddRequestHeader=apiendpointid,retailmilestone
- AddRequestHeader=appid,retail
- SecureHeaders
Wrapper App - This is a spring boot application which has Rest controller. Controller method does the following -
Identify JSON schema file basis the "apiendpointid" request
header attribute and apply JSON schema validation. Reject request in
case of schema validation failures by return 400 response to router
app.
Identity the freemarker request transformation file basis the "apiendpointid" request header attribute and transform incoming request to downstream expected format.
Send request to downstream.
Transform response from downstream to expected format again using freemarker response template.
Send response back to router app.
This works fine but there is an extra http "hop" from router to wrapper. We have not yet gone live; so not very sure if it will be a performance concern.
Currently wrapper is not built in a reactive way. Also team does not have much expertise in reactive programming. Are there any production implementations built this way (i.e. having this extra wrapper layer/app in the middle) or is it better to integrate all wrapper functionalities into router app itself? If yes, could you please direct me to some examples where request/response transformations/schema validations are being done in spring cloud gateway itself?
We have multiple API's running for an enterprise. As per our limitation client will allow only one static IP to receive all Inbound/Outbound requests.
So, we need to expose a single API as a bridge between the client system and API's running behind.
How to approach this design?
How to design the URL for this proxy API?
What edge functions does this API need to provide?
Any help would be highly appreciated. Thanks!
You do not need to use web services consumer, yet will need to create a POC.
Define A RAML with required path and RAML, scaffolding should give you API took kit, and connect an HTTP request
use HTTP request
Examples:
Define Headers --- attributes.headers.id etc
queryParams ---- attributes.queryParams.date
if you are sending JSON payload across from ex: postman, change Mime type to application/json
sample http properties for request
http.host=myHost
http.port=8872
http.base.path=/myproxy/services
I need to process MailGun webhooks. I did implement a solution directly on our web servers to process the webhooks, but MailGun generates so many calls from a large campaign that it effectively becomes a DOS attack.
One solution I've been looking at is using AWS API Gateway to a Lambda function to then push onto an SQS queue. We can then poll the queue at a rate we can manage. Unfortunately we can't get this to work as AWS API Gateway does not support multipart/form-data content types (which some of the webhooks are). This means that our SQS messages are not well formatted / structured. The best we can do is use the $util.escapeJavaScript($input.body) function in the mapping template to create an SQS message that contains the raw string of the webhook content (with escaped javascript chars) that is effectively unparsable i.e. we can't get data out of it.
I've had a go at using Zapier to process the webhook and push directly on the SQS queue. This can parse the various content types effectively and create a nicely structured message for us, but the cost of the service is not viable.
Has anybody managed this problem in another way? Are there solutions to API Gateway not parsing the content properly? I've deliberately stayed away from MailGuns event polling API as it involves significant delays before the polled data can be 'trusted' (according to MailGun).
Basically, is there another way of getting a nicely parsed message from content types multipart/form-data and application/x-www-form-urlencoded onto the queue?
Any ideas would be much appreciated!
To add, this link higlights issues with APS Gateway and multipart\form-data content:
API Gateway - Post multipart\form-data
As you've mentioned you can base64 encode in api gateway and call base64decode in the lambda function to retrieve the original payload (There are standard libraries in every language).
Also, note you can that you can use multipart form data for non file bodies.
Get non file body from multipart/form-data using AWS API Gateway and Lambda
I had the same challenge when building Suet. I ended up switching to Google Cloud functions which I really recommend. Don't waste time on Amazon API Gateway. Use Google Cloud Functions and use a middleware like multer. (You can see the source of Suet's webhook handler here).
Not sure if you ever came to a solution, but I have this working with the following settings.
Setup your API Gateway method to use "Use Lambda Proxy integration"
In your lambda (I use node.js) use busboy to work through the multi-part submission from the mailgun webhook. (use this post for help with busboy Busboy help)
Make sure that any code you are going to execute after all busboy is complete is executed in the 'finish' portion of the busboy code.
I am going thru the documentation and examples related to calling REST APIs for SugarCRM using Chrome REST client or PostMan but most of the examples are PHP and I am not finding a good way to find a proper request and other parameters to be mentioned so that I can get the successful response from the API. I was trying get_entry_list. Can someone please help by providing a working REST API request for this API which I can run on REST client or postman?
I also would like to know if I want to build a SugarCRM connector for my application, which set of APIs I should use? Should I go with REST or SOAP and any supporting arguments to choose one over another?
Thanks