AG-Grid's simpleHttpRequest

Aug 4, 2021

We use AG-Grid at work for several of our projects. Earlier this week, I ran into an interesting issue in some code being used to load data into the grid. The call was very simple:

agGrid.simpleHttpRequest({url: theURLToLoad })
    .then(function(data) {

This asynchronous call was failing and no error was being thrown (as we typically do elsewhere in our code). In looking around, I couldn't determine where the simpleHttpRequest call was defined. The AG-Grid documentation, which is generally pretty good, had no mention of it, save for its use in a few examples. After half an hour of digging, I decided to actually poke around in the AG-Grid source code. There I found the function's definition:

function simpleHttpRequest(params) {
    return new _utils__WEBPACK_IMPORTED_MODULE_0__["Promise"](function (resolve) {
        var httpRequest = new XMLHttpRequest();'GET', params.url);
        httpRequest.onreadystatechange = function () {
            if (httpRequest.readyState === 4 && httpRequest.status === 200) {

All this function is an incredibly light-weight wrapper around XMLHttpRequest. It provides absolutely no support for error handling, and is missing all the other hooks one would need to take full control over the request and its response. It frustrates me when packages do stuff like this. If you're going to show how to fetch remote data for your package, use the vanilla JavaScript features that are industry standard, not some custom wrapper.

Add a Comment
Ignore this field:
Leave this blank:
Optional; will not be indexed
Ignore this field:
Both Markdown and a limited set of HTML tags are supported
Leave this empty: