"RESPONSE PAYLOAD" code example

Example 1: javascript get response payload

try {
  const response = await fetch(url, {
          method: "PUT",
        });

   if (response.ok) {
     const data = await response.text();
   }
} catch (e) {
 console.log(e) 
}

Example 2: How do you access the payload of the response

response.getBody()
response.body()
 
Request:
- GET HTTP method
- API endpoint/URL: IP:8000/api/hello
- No headers but we could add:
Accept - Json
Response:

We verified the response:
- status code -> 200
- Headers:
- ContentType
- Date
- Content-length
- Body/PayLoad: that it contains expected data.

Tags:

Misc Example