Layer7 API Management

 View Only
  • 1.  Log JSON Request/Response payload Size

    Posted Apr 10, 2018 06:57 AM

    Hi All,

     

    I need to log the size of incoming JSON request  as well as the size of response returned. I've tried with some the context variable,but all i'm getting is length of the payload[total characters in request body part]. What is the possible way to log the size in bytes?

     

    #jsonpayloadsize #logsize 



  • 2.  Re: Log JSON Request/Response payload Size

    Posted Apr 10, 2018 07:12 AM

    Have you tried using ${request.mainpart.size} and ${response.mainpart.size}?



  • 3.  Re: Log JSON Request/Response payload Size

    Posted Apr 10, 2018 07:23 AM

    Yes, and in both case it's giving length of the request and not the size.



  • 4.  Re: Log JSON Request/Response payload Size
    Best Answer

    Posted Apr 10, 2018 08:44 AM

    Since a json payload consists of nothing but characters of 1 byte size each, the number logged by these variables would be the total size of payload which is length * 1 byte.

     

    So the length of below json payload will be 7 and its size will be 7 bytes

    {"1":1}

     

    pretty printed json below will have 13 as length and 13 bytes will be its size

    {

       "1": 1

    }



  • 5.  Re: Log JSON Request/Response payload Size

    Posted Apr 11, 2018 05:06 AM

    thank you for above explanation, but i've got one more question, while getting the size of whole request, i don't see any change in size compared to size of only mainpart whereas i've passed plenty of header. how could i get the size of whole request? i;ve tried ${request.size} but it gives same result as ${request.mainpart.size}.