How can I mediate the JSON response of my API - wso2-api-manager

Following one of the examples in the WSO2 documentation, I am invoking the Yahoo Weather API. However, I would like to return a subset of the API's response values and rename some of them (e.g., return the only next day's High and Low and call them "NextDayHigh" and "NextDayLow".
Should I create a Script Mediator and manipulate the JSON that way? How do I reference the individual fields from Yahoo's response and map them into a JSON response that I create?

Related

Firebase REST API get all data from node as JSON Array

Is there any possibility in Firebase to get data from node as JSON array, but not like multiple objects
For example I have:
https://additive-food-e2a9a.firebaseio.com/additive.json
{"-KjrTAOehl0RAvKYlYVp":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrUIm-itn8h8EjckNQ":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrXlvuJjMuogCJmGDK":{"alias":"Curcumin","danger":"2","name":"E100"}}
But I need something like:
[{"-KjrTAOehl0RAvKYlYVp":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrUIm-itn8h8EjckNQ":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrXlvuJjMuogCJmGDK":{"alias":"Curcumin","danger":"2","name":"E100"}]
Firebase returns only JSON object when you hit GET request to the node. You have to apply JSON parsing logic in Java, Javascript or whatever language you use.
Sample JSON Parsing logic in Java.

Use trace data as metric in Application Insights

Is it possible to mark data from a trace as being a metric?
E.g. if i have a trace with a JSON message, would I be able to mark a field in the JSON document as a metric.
Does it even make sense doing so, or are there better alternatives? I just want to be able to track/graph and receive alerts on the field in the JSON document.
The closest thing i can think of would be to parse out the metric part of your json document, and actually send it as a metric in your trace call?
string theMessage = whatever;
// .. code to parse apart the message, find the json, and grab metric values
// and put them into a dictionary<string,double>
// and any other string values into a dictionary<string,string>
telemetryClient.TrackTrace( theMessage,
optionalDictionaryOfStringToStringProperties,
optionalDictionaryOfStringToDoubleMetricValues );
there's no "automatic" way to do what you want, having the backend parse out values from a trace that contains json.
However, you could parse those values back out in a query if you're using the analytics portal. the query language there lets you do string manipulations, parsing, json parsing, etc. so if you just need it downstream for some kind of analysis, you don't need to do any of that, just do it in the query.

Multiple parameters send as json in body RetroFit without creating a model to hold it

I want to use RetroFit for Android but I donĀ“t like the idea of creating a model for every single request.
Can I create a Service that receive like 2 strings and convert it into a json that should go in the body of the post request?
You can create a HashMap and put it as parameter of your request method. For example, something like this:
#Body HashMap user

JSON + SOAP - Is DataContract necessary?

Here's my problem.
I'm using SOAP to retrieve information from a third-party web service.
Response time is too high, so I was planning on using JSON instead, at least in a couple of methods.
For this I'm using DataContractJsonSerializer, but I seem to be having some trouble.
For example, in SOAP there's a method called getAvailablePublic with returns an object of type getAvailablePublicResponse.
There's an equivalent for this method in JSON, which also returns a an object of type getAvailablePublicResponse.
In order to deserialize the information I needed to create a couple of data contracts, and here are my concerns:
Do I really need to create a DataContract? Why can't I use getAvailablePublicResponse object from asmx?
The problem is that if I create a DataContract, I need to use a different name other than getAvailablePublicResponse, as I would have two objects with the same name (the one created by me, and the one from SOAP), and this would require making several changes in my solution.
Hope this makes sense.
Thanks.
Can you post your client code that is making the call to the web service? I don't know what you are using now, but I'm a fan of RestSharp for making remote calls and serializing JSON to C# classes. Something like this:
RestClient client = new RestClient("http://some.domain.com/someservice?someparam=yes");
var results = client.Execute<MyGreatDTOClass>(new RestRequest(Method.GET));

How to correlate the request and response for the purpose of logging

I'm using the Global filters to log the request/response which works fine, but now I'd like to embed a correlation ID (Guid) in both to that I may tie the 2 together. What's preferred way to do this?
Thank you,
Stephen
Not sure if you are taking about these but you could do this with ServiceStack Request and Response filters Sounds like you want to do something like this...
Create the Guid in the Request Attribute Filter and save to db.
While still in the request filter store that Guid in into the IHttpRequest.Items dictionary. This dictionary is for you to use for anything you want. It will be avilable to all the ServiceStack services.
Access that Guid in the Response Attribute filter via the IHttpRequest variable and save response entry to database.

Resources