In the previous lesson, the CatFact API responded with JSON data, so we used the response.json()
method to process it. However, APIs can return data in various formats, such as plain text, binary data, or form data.
The Fetch API provides multiple methods to handle the response body based on the data type returned. Here are some of them:
response.text()
Use this for plain text like .txt or .csv files.
response.json()
Use this for APIs that return structured JSON data.
response.blob()
Use this for binary data like images, videos, or files.
response.formData()
Use this for handling form submissions.