Forum Discussion

ravienu's avatar
ravienu
Occasional Contributor
3 years ago

encoding of utf-8 is set for some APIs test cases and not for some in project properties

Hi mates,

 

I am sending unicode characters in Json request payload. The server is returning "NO success" response. But If I add encoding as UTF-8 in that test case(REST) properties, response comes as "SUCCESS". Is it the the right thing to send UTF-8 explicitly ? And if yes, how does this will be addressed when any integrations call that API ?

 

And, I could see some other APIs test cases shows UTF-8 as encoding by default in ReadyAPI. So, not sure whats going on.

 

Appreciate any help.

 

Thanks.

Ravi.

 

 

  • richie's avatar
    richie
    Community Hero

    Hey ravienu,

    Im a bit confused and also im a bit too literal sometimes, so youll have to bear with me.

    Unicode is a character set
    UTF-8 is character encoding

    So! Theyre related but are completely different.

    Within ReadyAPI you have some system properties (available via the Help menu option) and within here youll see some encoding parameters that are global....ive just had a look at mine and it says cp1252 for sun.encoding and file.encoding parms.

    You can override this explicitly and it sounds like youve done this, specifying UTF-8.

    To answer your question, yes....its completely reasonable to be explicit with your encoding. You dont mention what payloads youre submitting, but xml includes the char encoding and xml version in the xml declaration at the top of the xml instance, although the requirement for this has relaxed. Regarding json, previous earlier versions of json didnt require encoding, but more recent versions of software that support parsing json uses UTF-8 as the encode.

    Whether your api needs the explicit encoding is entirely up to how its been coded and the requirements of the system.

    Hhmm...not sure if i actually helped at all.....🤷‍♂️😉

     

    Oh.  One more thing.  If no explicit encoding is set for json then its just plain text rules (no encoding) and if i can remember correctly i think thats iso-8859......i think.....

    Cheers,

    Rich

    • giovanni_favara's avatar
      giovanni_favara
      Contributor

      Hello ravienu ,
      what richie wrote is correct. I'd like to add a different perspective to richie's answer.

       

      Each system or systems behind an API is different and in part follows an individual configuration or implementation, complying with some standards or not.

       

      A good API also has good documentation. If this documentation, preferably with OpenAPI, defines that only UTF-8 is accepted and this specification is mandatory, then the character encoding must also be specified according to the documentation. It is not defined in HTTP that if nothing is specified then the message must be interpreted as UTF-8.

       

      It is good practice, if the message is not encoded in ASCII, to supply the character encoding. Only with ASCII characters can one assume that the characters will definitely be interpreted correctly - but in practice there is no guarantee of this. Always remember, no system or API is always correctly configured or implemented. Always take the safe route and always specify the character encoding.

       

      Cheers,
      Giovanni