HTTP Response body type in RAML for an API - mule

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.

Related

Authorization Endpoint does not support data in the RequestBody as required by Section 4.2.1 Authorization Request of the OAuth 2.0 standard

Section 4.1.1. Authorization Request states:
The client constructs the request URI by adding the following
parameters to the query component of the authorization endpoint URI
using the application/x-www-form-urlencoded format, per Appendix B:
The use of the Content:Type x-www-form-urlencoded forces the request parameters to be sent in the body and not the query header. However, when submitted this way the authorization server returns an error indicating it cannot locate the client_id.
Is there a setting I need to change to support the request in the body rather than in the header?

.NET Service reference sending wrong accept header (text/plain)

I've created an ASP.NET Core web application, and installed + used the Swashbuckle.AspNetCore version 6.1.5 Nuget package. This hosts the following openapi document on https://example.com/swagger/v1/swagger.json.
Also my API supports content-negotiation.
When sending no Accept header, or Accept: text/xml header, the api will return an XML string
When sending an Accept: application/json header, the api will return a JSON string
Now I've tried consuming my api through the swagger document:
Create a new .NET Core console application
Right-click the project file → Add → Service Reference
OpenAPI
URL: https://example.com/swagger/v1/swagger.json
Namespace: Example.Api
Class name: ExampleClient
You can then write a Main like this:
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var httpClient = new System.Net.Http.HttpClient();
// httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
var mintPlayerClient = new MintPlayer.Api.MintPlayerClient("https://mintplayer.com", httpClient);
var artists = await mintPlayerClient.ApiArtistListAsync(false);
}
Now when you debug the console app
navigate to the ApiArtistListAsync method in the swaggerClient class
put a breakpoint at the client_.SendAsync call
you can now inspect what the swaggerClient is sending to the webservice
Usually it's like this:
SOAP = XML
REST = JSON
Even when adding a DefaultRequestHeader on the HttpClient the response from the HttpClient is an XML, because it's explicitly added inside the SwaggerClient method:
And here is how the code is generated + the line where the Accept header is explicitly set (swaggerClient:430). This is auto-generated code from adding the service-reference.
So why is the Accept header in the generated code explicitly set to text/plain? Why isn't the default accept header value application/json, since this is a REST service?
I think you might want to check this on both side, client(your console) and server(your api project).
We all know that usually
SOAP = XML
REST = JSON
But you're coding the whole things, total in-control of what being send and what being response.
Let's assume you client send Accept-Header which support both text/xml and text/plain (which as i understand here, you expect a response as text/plain).
Then the server realize that your console is happy with either text/xml and text/plain, and the server itself support all kind of common format.
So it'll have to electing the most convenient format to response to the client.
Which in this case is text/xml.
That's so, the console received and happy with text/xml response format either way
And if that's the case, that I get you right, you want to receive text/plain on the console, then make sure the only Accept header sending out is text/plain or do some custom logic on your API to choose the text/plain format over others when sending response.

Unable to test an API in JMeter where I need to upload a file

can someone please help me with uploading a file on JMeter I feel its very tricky thing...
let me share the screen shot of what I've done
enter image description here
Its failing with below error:
Thread Name:jp#gc - Ultimate Thread Group 2-4
Sample Start:2021-02-04 17:28:44 IST
Load time:562
Connect Time:0
Latency:562
Size in bytes:595
Sent bytes:84568
Headers size in bytes:446
Body size in bytes:149
Sample Count:1
Error Count:1
Data type ("text"|"bin"|""):text
Response code:500
Response message:
HTTPSampleResult fields:
ContentType: application/json
DataEncoding: null
Response Body:
{"timestamp":"2021-02-04T11:58:45.482+00:00","status":500,"error":"Internal Server Error","message":"","path":"/pps/storage/upload-image"}
Request Body:
POST https://pixelperfectdevexternal.useready.com/pps/storage/upload-image
POST data:
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl
Content-Disposition: form-data; name="filename"
Content-Type: image/jpeg; charset=US-ASCII
Content-Transfer-Encoding: 8bit
${filename}
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl
Content-Disposition: form-data; name="filename"; filename="Passport size photo.jpeg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl--
I'm totally stuck on this from last 3 weeks, I did what was told in tutorials and still its not working, someone please help me out.
We don't know how to fix the issue because we don't know how the request should look like, moreover you don't show us "Parameters" tab of the HTTP Request sampler and HTTP Header Manager configuration.
So if you have another way of successfully calling this API like curl or Postman or other tool - you should be able to record the request using JMeter's HTTP(S) Test Script Recorder, see How to Convert Your Postman API Tests to JMeter for Scaling article for example setup.
If not, you need to check your API endpoint documentation, application logs or ask around for the proper request format, once you know it you should be able to amend the request yourself or provide us more details so we could assist.

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

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!

multipart/form-data Possible?

I am using Google Cloud Endpoints with JWT Authorization and I am trying to Upload File from API.
There is no Issue with JWT as it is already working correctly with all other types ex. [application/JSON].
API POST Call (api/document/processrequest) with Content Type as multipart/form-data is saying Bad Format Response from Google Endpoints for Same Token.
API Post Call (api/document/processrequest) with ContentType (application/JSON) have no issues.
Is Google Cloud Point not supporting multipart/form-data?
Authorization Token is passed in Header. Authorization: Bearer [Token]
Everything works fine in Localhost/Development Environment without Endpoint.
Error Generated In Stackdriver Log:
Firebug error sample call:
Firebug success sample call with application/json:
I have specified application/JSON and multipart/form-data both in openapi specification.
Endpoints does not support multipart/form-data.