HTTPRequestLogger.cfc
Like a lot of developers, I we make a lot of external API calls. One thing that can come up when dealing with outside vendors is that sometimes the API connections don't work as expected. On those ocassions, the vender will ask us exactly what data we sent them.
I always want to know the answer.
So, we send our requests through HTTPRequestLogger.cfc. This runs on top of DataMgr.
Initialization is simple:
oHTTPRequestLogger = new com.sebtools.HTTPRequestLogger(oDataMgr);
After that, simply call the "runRequest" method, which has the following method signature:
- Attribs (struct, required): What attributes you would like for the cfhttp call.
- Params (array, required): An array of structures for cfhttpparam calls.
- log (boolean, default=true): Indicates if the request should be logged.
- log_results (boolean, default=true): Indicates if the result should be logged.
If you would rather do the request and logging separately, just call the "logRequest" method, which as the following method signature.
- Attribs (struct, required): What attributes you would like for the cfhttp call.
- Params (array, required): An array of structures for cfhttpparam calls.
- Result (struct, optional): The results of the HTTP call.
- ProcessTimeMS (numeric, optional): How many milliseconds the call took.
- MetaQueryString (string, optional): A query-string formatted data of any additional information that you want.
The request, response, processing time, date, and URL will all be logged in the "logHTTPs" table.
Do note that you will need to be careful not to log sensitive data that you shouldn't have stored in the database. You may have data stored encrypted in your database, but sent unencrypted to some service. If so, be careful not to use this tool to store that data in clear text.
HTTPRequestLogger is part of my com.sebtools package. It is a free ColdFusion package and you can read more about it in my com.sebtools blog series. Check it out!
If you need any help with com.sebtools, or ColdFusion in general, let me know.
There are no comments for this entry.
[Add Comment]