In IBM Api connect Unable to Change the response Content-Type to “application/json; charset=UTF-8” - apiconnect

I am using apic.setvariable('message.headers.Content-Type', 'application/json; charset=UTF-8'); property in gateway script to change response header. Which is not working.
Suspecting, the content-type is not charset=utf8, which in turn overwriting the content-type header. How to use Map Policy to transform the response body to charset=utf-8?
Any help would be appreciated!

Related

"Content-Type" for HEAD request

I'm building a REST API. Before calling a GET endpoint a HEAD request should be sent.
What kind of "Content-Type" parameter should a HEAD request provide?
Its not mandatory to send HEAD request before sending GET request. The HTTP HEAD method requests the headers that would be returned if the HEAD request's URL was instead requested with the HTTP GET method. HEAD request/response have no body so there is no need of Content-Type header

Content-Encoding response header not returned in karate GET call

Actually I was trying to migrate my old test suite to Karate framework.
And I have to validate response headers, In that "Content-Encoding" header is not returned in Karate GET call - I checked it in results I could see all other response headers but not "Content-Encoding" and returns null for assertion.
The same GET call I checked it in chrome browser - developer console and POSTMAN in both the tools I could get "Content-Encoding" but not in Karate.
Please help me in this.
If the server returns Content-Encoding you will see it else you will not.
To validate that a header does NOT exist, it is simple:
And match responseHeaders contains { 'Content-Encoding': '#notpresent' }
Refer responseHeaders: https://github.com/intuit/karate#responseheaders
Unfortunately it does not provide all response headers, because some, like "Content-Encoding: gzip" are stripped away by underlying Apache http libraries after decompressing the content it seems.
See:
Having trouble getting content-encoding to show up in response header for get request

Set HTTP requests defaults in IntelliJ HTTP request client editor

In IntelliJ http request editor; is there a way to set the common config for all the requests in the file (and globally) ?
For example I would like to specify an authorization header for all the requests.
Current code
GET http://localhost:8080/api/foo
Authorization: Bearer my-token
The code I am trying to achieve:
Desirable code
<common headers>
Authorization: Bearer my-token
GET http://localhost:8080/api/foo
GET http://localhost:8080/api/bar
GET http://localhost:8080/api/baz
It's a bit late but i will try to give an answer in case someone is coming around.
I'm not sure it is exactly what you are looking for but maybe it help.
If you are getting your token dynamically from a login endpoint, you can store the token in a variable and use it later in any request.
Exemple:
### Login
POST http://localhost:8080/login
Content-Type: application/json
{
"email": "someEmail",
"password": "somePassword"
}
> {%
client.global.set("auth_token", response.headers.valuesOf('x-auth-token')[0]);
%}
### Get user
GET http://localhost:8080/user/someUserId
Authorization: Bearer {{auth_token}}
In this case, i store my token coming from the header x-auth-token in a variable auth_token. Than i use it in the authorization header for all my next requests.
Found from the official JetBrains website HTTP response handling exemples
Have a nice day!

HTTP Response body type in RAML for an API

I am creating an API with Mule Anypoint Design center, where I receive data with type text/plain from other endpoints. Can I just use text/plain in below raml code instead of application/json?
Why am I asking this?
My endpoint is AWS SNS and it sends, a HTTP header, Content-Type, with value "text/plain" only and the apikit router in studio validates whether the content-type is "whatever specified in RAML spec(application/json)". Ofcourse I can disable validations, but I have other things to validate which depends on it.
responses:
201:
body:
application/json:
example: {"msg" : "Flight inserted successfully"}
Yes you can change it to text/plain in RAML if needed. But if you want your response to be json, you'd be better off transforming your payload and overwriting the Content-type header in Mule/Anypoint design center.

Unable to programmatically set Content-Type in BizTalk Wcf-Custom response port

I am attempting to receive JSON messages into BizTalk using the bLogical REST Start Kit for BizTalk (http://biztalkrest.codeplex.com/).
I am able to successfully receive a message, transform it, and return a response from my Orchestration, but when I transform the response back out through the BizTalkRESTResponseHandler, the HTTP Content-Type is being forced back to 'application/xml', even though I'm explicitly setting it to 'application/json'. The Content-Type is confirmed by tracing the Request and Response in Fiddler, as well as SoapUI.
The Accept: value on the Request is 'application/json'
Any ideas how I can trace further into the Wcf-Custom adapter stack to see where the Content-Type is being reset?
You can solve this by adding a HttpResponseMessageProperty before returning the message in the IDispatchMessageInspector. You can either do this directly in the BizTalkRESTResponseHandler IDispatchMessageInspector or in a separate one.
To do it in the BizTalkRESTResponseHandler get the source and add the following 3 lines of code in the BeforeSendReply method just above the "reply = newReply" in the end.
HttpResponseMessageProperty prop = new HttpResponseMessageProperty();
newReply.Properties.Add(HttpResponseMessageProperty.Name, prop);
prop.Headers.Add("Content-Type", "application/json;charset=utf-8");
Now instead of getting:
You will get this: