RAML -> APIKit flows:how to generate representations based on Accept header? - header

I have a RAML spec with both application/xml and application/json as representation for the response body, based on the HTTP Accept request header. APIKit only generates flows for one of the two formats. What can I do to create a mocking service that responds with both json and xml based on this construct?

I resolved this issue by updating the RAML file
Update Accept in header
Also updated Response body with 2 example
apikit routes based on resources and methods only.
You'll need to use a choice router to set the different payloads depending on the 'accept'

Related

What's different between "ResponseCache attribute" and "ResponseCache middleware" in asp.net core?

I know ResponseCache attribute can caching page in client side by http headers attribute cache-control.
And ResponseCache middleware, it caching page on server (same http headers as ResponseCache attribute).
I compare these, it seems no different, same features, same condition.
Server side caching is no different from ResponseCache attribute, they both don't let the request into controller action, or these have different request pipeline ?
So, What kind of scenarios would choose ResponseCache middleware/ ResponseCache attribute?
From documentations and source code, we can find:
Response Caching Middleware
determines when responses are cacheable, stores responses, and serves responses from cache.
ResponseCache Attribute
specifies the parameters necessary for setting appropriate headers in response caching.
It is used to configure and create (via IFilterFactory) a ResponseCacheFilter. The ResponseCacheFilter performs the work of updating the appropriate HTTP headers and features of the response. The filter:
Removes any existing headers for Vary, Cache-Control, and Pragma.
Writes out the appropriate headers based on the properties set in the ResponseCacheAttribute.
Updates the response caching HTTP feature if VaryByQueryKeys is set.
For more information, please check:
ResponseCachingMiddleware source
code
ResponseCacheAttribute source code

Mule ESB Flow to pass parameters in Calling SOAP Webservice

I have created on flow in MuleESB which is calling a web-service without any parameter just sending it username, password and token in a property and it is working fine.
But the second API I want to post some parameters while calling soap request but I don't know how to use it I tried to pass through set payload but no response.
use Webservice consumer and add a transform message component beofre it. by doing so you can automatically map all the parameters which are required by the SOAP webservice, as datasence will automaticall download the meta deta of the service using the WSDL file.
Make sure you select application/xml as content type in Postman or SOAP UI and select POST.
Use CXF and select Operation as Proxy Service ,Provide details. Selct and provode (WSDL,MTOM enabled,SOAP Headers ,SOAP 1.2)
Make sure you posting XML request "POST" method in allowed methods.
Use 2 transformers. XML to DOM and DOM to XML.
Log the request using
#[message.payloadAs(java.lang.String)]
Use a groovy script transformer to retreive the entire payload.
def userSoapRequest = new XmlSlurper().parseText(payload);
def userId = userSoapRequest.userId.text();
message.setInvocationProperty('userId', userId);
6.Retrieve userId like above and similarly for all the elements.
7.Process them as you want.
Hope this helps

How do I get the response object in a bayeux server response in CometD

I am trying to customize the response of a bayeux server response so that i can add some header parameters before sending it back to UI. I am able to add header values in the request using customize method in a LongPollingTransport. Much help needed.
CometD tries to abstract away from the underlying protocol.
When you use WebSocket, for example, the concepts of request headers and response headers simply do not exist anymore.
As such, it is way better that if you have additional information to send to the client, well that additional information should go in the CometD messages rather than in HTTP headers.
Furthermore, when using HTTP as a transport, a single HTTP response may carry multiple messages, so it is not clear to what CometD message the additional information would refer to.
Your question is too generic (does not say why you want to add headers, does not say what specific header, etc.) to get a precise answer, but bottom line is that you typically don't want to use HTTP headers with CometD.

Changing response serializer for a particular call inside AFHTTPSessionManager

I am subclassing AFHTTPSessionManager to make different POST requests to one server. All responses from the server are returned in JSON format, so I set response serializer for AFHTTPSessionManager to AFJSONResponseSerializer. But for one POST request I need to change response serializer to some other (leaving all other to use AFJSONResponseSerializer). Is is possible to do that?
Try AFCompoundResponseSerializer, you may add different serializers in it.

API controller MVC 4 - return type

in the HTTPGet API method, it seems like by default it will return the object in XML format. How can i make it to return in JSon format?
The ASP.NET Web API has a built-in content negotiation, you just need to specify in your HTTP request's Accept header field that you want json instead of xml.
You can start to learn more about content negotiation in this article.