Search code examples
karateraw

Karate: How to send raw request and disable embedded expressions


How can I send a raw request wrapped in parentheses and prevent Karate from parsing it as "embedded expression"?

Example 1: Correctly sends the string '(1+2)' as payload (as expected).

Given request '(1+2)'

Example 2: The same string as multi-line is detected as "embedded expression" and converted by Karate to type number 3 (you can see it clearly in the logs and in the receiving API):

Given request
"""
(1+2)
"""

Why is that and how can I send real raw strings, no matter what's inside? In other words: How to disable embedded expressions?

My background is that I need to send multi-line raw strings as payload. Some sub-strings are wrapped in parentheses and this would then lead to errors in the receiving API (to simplify my question I reduced the examples to 1 line).


Solution

  • Use text: https://github.com/intuit/karate#text

    * url 'https://httpbin.org'
    * path 'anything'
    * text body =
    """
    (1+2)
    """
    * request body
    * method post
    

    Refer to the docs for "type conversion" also. And another reference: https://stackoverflow.com/a/64328206/143475