Add text example to Fetch API's Response object article



2 years ago
2 years ago


(Reporter: machineghost, Unassigned)






2 years ago
:: Developer Documentation Request

      Request Type: New Documentation
     Gecko Version: unspecified
 Technical Contact: 

:: Details

Your MDN documentation is normally stellar, and I always pick it over those idiots at W3 Schools.  However, when I was reading the documentation for the Response object (returned from a "fetch"), I realized that someone made a poor choice when creating the example.

I say this because the example demonstrates how to fetch a binary object (in this case a jpeg) using fetch.  However, 99.9% of AJAX requests on the web aren't for images, or any other binary file: they're for text (usually, but not always JSON).  Because the example demonstrates the binary data case, it completely fails to explain the far more common text case.  As a result I was forced to leave MDN to go figure out how Response works somewhere else.

A very simple "here's how you fetch some JSON text" example would probably be very easy to write, and (I think) would be far more useful to most developers.


2 years ago
Component: JavaScript → API: DOM

Comment 1

2 years ago
P.S. Having learned the basic pattern:

    .then((response) => response.json())
    .then((json) => doSomething(json))

it certainly seems so basic and simple that there's no need for an example.  But if you don't have the proper frame of reference and all you have is the API definition of the json method of Response (which returns a promise, not the json of the response, contrary to what one might naively expect), then it can be hard to get to the above pattern ... which is why I think even a simple example could be valuable to new learners.
Personally, I feel we should have both a binary example and a text example here, rather than replacing the binary example we currently have.

Comment 4

2 years ago
@sheppy I wholeheartedly agree.  I just meant that the non-binary case was, of the two, more useful to more people.

But if multiple examples are possible then I think one for each case would be great, as the two cases are unique enough that they would each illustrate something different and wouldn't be redundant.
Summary: Example for "Response" Is Poorly Chosen → Add text example to Fetch API's Response object article
You need to log in before you can comment on or make changes to this bug.