HTTP Response body type in RAML for an API

917 Views Asked by At

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"}
2

There are 2 best solutions below

2
On

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.

0
On

As of March 2023, Amazon SNS now supports custom Content-Type headers for HTTP messages delivered from topics. Here's the announcement: https://aws.amazon.com/about-aws/whats-new/2023/03/amazon-sns-content-type-request-headers-http-s-notifications/

You simply have to modify the DeliveryPolicy attribute of your Amazon SNS subscription, setting the headerContentType property to application/json, application/xml, or any other value supported. You can find all values supported here: https://docs.aws.amazon.com/sns/latest/dg/sns-message-delivery-retries.html#creating-delivery-policy

{
    "healthyRetryPolicy": {
        "minDelayTarget": 1,
        "maxDelayTarget": 60,
        "numRetries": 50,
        "numNoDelayRetries": 3,
        "numMinDelayRetries": 2,
        "numMaxDelayRetries": 35,
        "backoffFunction": "exponential"
    },
    "throttlePolicy": {
        "maxReceivesPerSecond": 10
    },
    "requestPolicy": {
        "headerContentType": "application/json"
    }
}

You set the DeliveryPolicy attribute by calling either the Subscribe or the SetSubscriptionAttributes API action: