Logging the full request (headers + body) of a REST call.

0
I have to log the full request of a REST POST call. This would include at least the location, headers and body of the request. If possible preferably the complete cURL.  Any idea how to do this?
asked
3 answers
2

It is currently not possible to do this directly from the CallRest-activity, but there is a module for that: Consumption history. You do need to wrap the CallRest-activity in 3 other activities. It contains toggles to only use it in non-production, and for retention-time, useful since the log can fill up quickly if you store each json for each call.

By the way, it also remembers the response-time and will keep metadata, being the number of calls to each interface per day and the average response time so you have a nice graph of the past performances.

 

answered
2

Do the following, create a export mapping for your API call that you want to make. Use that to generate a JSON string value and store that in a variable.

 

Then make another mapping for HttpRequest + HttpHeaders from the System module taking into account all attributes from HttpMessage/HttpRequest/HttpHeader. This should then cover contents/uri/header information.

 

Create the HttpRequest entity + list of headers as required to make the webservice call.

 

Fill in the information, use the first generated JSON as your content on HttpRequest.

Use a string variable to point to the Uri resource you will call in a microflow using the Call REST service action and set that in the HttpRequest Uri attribute on the HttpRequest entity before exporting it to JSON.

 

Use the export mapping you created for HttpRequest on the just formed request. Keep this in a filedocument or string variable. 

 

Call the webservice using "Custom request template" and only at this point I'm not entirely sure you want to be using the first JSON or the second JSON containing the full request including the headers as the only {1} parameter for that content. As headers is a separate tab on that pop-up. So you'll have to play around with that.

 

Anyhow you can then store all these things in an entity that you store in your Mendix database or offload it to some data warehouse.

Including the possibility to store POST/PATCH methods etc. And you can do the same for the responses coming back, link them up, track API call duration etc.

 

Just make sure to weigh the benefits of having all this information versus the performance impact of creating an additional export mapping step and storing that.

answered
1

Hi Joel, you can change the log level for:

 

REST Consume: Logs messages related to the Call REST service activity.

REST Publish: Logs messages related to published REST services.

 

See these documentation pages for more info:

https://docs.mendix.com/refguide/logging/ 

https://docs.mendix.com/howto/monitoring-troubleshooting/log-levels/

 

 

answered