how to change the response body from apche-apisix? - apache-apisix

i need to parse json from backend and modify it, for example remove urls for pagination, the consumer don't want it. And i can't modify this in backend.
how to do this with response-rewrite plugin. getting response from backend in variable and do json parsing...

You can configure filters in this plugin to replace certain content
ref: https://apisix.apache.org/docs/apisix/plugins/response-rewrite/

Related

Why is my HTTP request URL not being generated for a Logic App?

Good morning. I am new to logic apps and I am trying to figure out how I can trigger the execution based on a GET URL with three parameters. All the examples I've found on Google show the URL being generated once the JSON and relative path is entered, but that's not happening for me. Perhaps it's because I am creating the logic app in VS.
Here's what my "When a HTTP request is received" step looks like in the logic app.
I also tried removing the JSON and just using the parameters to pass the values to the function, as shown below. I'm just not sure the best way to do this.
All I really need to do is get the three parameters into the logic app so I can perform a function call with the parameters. Any suggestions would be greatly appreciated!
Why is my HTTP request URL not being generated for a Logic App?
You need to click save, and then the url will be automatically generated for the When a HTTP request is received trigger:
You can use this expression to accept values through GET parameters:
triggerOutputs()['queries']['parameter-name']
For example:
Noteļ¼š
Queries need to pass parameters in the form of json.

How to extract data from AMQP request in JMeter

I have used AMQP Publisher to publish the message in RabbitMQ then I use AMQP Consumer as listener. In the View Results Tree the messages from the queue in shown in the request tab of AMQP Consumer. My question is how to extract data from that request. I tried following the Bean Shell Post Processor but it seems it will only work on Http request. I tried to use JSR223 Post Processor and XPath extractor but it doesn't work as well. Any help?
I wanted to extract the documentId from the request. Here is the Request pattern.
I have already tried following links:
Extracting value from jmeter post request
how to extract value from request in Jmeter
How to extract the values from request input xml in jmeter
The statement that you tried something without sharing the code doesn't make sense
Posting JSON data or code as image is not the best idea
Any reason to extract data from the request? Normally people know everything about the request hence don't require to extract anything from it. Even if they do - they should normally able to store the request data into a JMeter Variable and apply the relevant Post-Processor to it.
Whatever, just in case here is the solution:
Add JSR223 PostProcessor (if you really want to do this using the Post-Processor) as a child of the request
Put the following code into "Script" area:
vars.put('foo', com.jayway.jsonpath.JsonPath.read(sampler.getArguments().getArgument(0).value,'$..documentId')[0])
That's it, you should be able to access the extracted value as ${foo} where required.
References:
JsonPath: Getting Started
Apache Groovy - Why and How You Should Use It

How log request and response body in Istio

I'd like to log request and response body from incoming traffic to each my microservice.
Is it possible in Istio (Envoy) out-of-the-box?
I don't see body attribute for mapping in Mixer's EntryLog.
Maybe it will be added in future version of Istio?
Of course I can achieve this by implementing my own filter in microservise, but maybe there is better solution to achieve this.
If I understand your question correctly, then you should check out this documentation of Lua filters.
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#script-examples
body = handle:body() should give you the request or response body, depending upon the handle.
handle:logInfo(message) should help you log it.
For me print statement also had worked.
e.g. print(headers["Cache-Control"]) was putting the header value in the log of my app on GCP project's kubernetes cluster.
You need to apply an EnvoyFilter in your kubernetes cluster and in the lua code, you can log the request body.
Also keep in mind that 'The filter should be configured with the name envoy.lua' ONLY

Talend tRESTClient does not work

I have a Talend job which has an input CSV file which needs to be converted to a JSON format and then using a tRESTclient/tREST , make a HTTP call request and post data.
In the current job, I have an Elasticsearch server installed on my local machine and provided that URL.
I was able to convert the files to JSON format and also verified with a tlogrow component but unable to post data.
(P.S: I was able to post data using a bulk Java code, loading jar files and making HTTP call and sending parameters using a tJAVArow component. So no issue with my localhost and posting data.)
After converting the data from input file to JSON format, set the context variable with your JSON data and then make the rest call. You can add the context variable in the HHTP Body. example : context.json_post without double quotes.

Problem with Google AJAX Search API RESTful interface

When I send the following query
http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=coffee%20New%20York%20NY
using c# WebClient.DownloadString function or ordinary web browser
I get JSON data which is different from data for the same query using JavaScript and
Google AJAX Search API.
From REST service I get the following url field
http://www.google.com/maps/place?source003duds0026q003dcoffee0026cid003d13245583795745066822
but from JavaScript query I get this url field
http://www.google.com/maps/place?source=uds&q=coffee&cid=13245583795745066822
The problem with REST service answer is that the url it gives points
to a web page with error message "We currently do not support the location".
What am I doing wrong?
It looks like either you are decoding the URI from the REST request incorrectly, or Google is ending it wrong. The = are being sent or parsed as 003d and the & as 0026
EDIT : After trying that link I see they return the links, in the JSON, with the '=' and '&' encoded, the JavaScript must be replacing those characters for you automatically. You could do a simple String replace on "003d" and "0026" - although I'm not sure that will cover every use case.
I resolved this by parsing JSON data with Json.NET library http://json.codeplex.com/

Resources