Obtaining [Symbol(Response internals)] through a JSON response

I am currently utilizing the library isomorphic-unfetch to retrieve JSON data from a Rest API. Here is my approach for making the request:

    const res = await fetch(
      `url`
    );

To extract the body, I simply do:

    const response = await res.json()

However, I am unsure about how to access the response headers. When I log the response to my server's console, this is the information displayed:

Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    // stuff
  },
  [Symbol(Response internals)]: {
    url: 'request url',
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

I am curious about the Symbol(Response internals) and how I can access its headers property. Can anyone assist me with this?

Answer №1

If you need to access the headers of a response, you can do so in the following ways:

const response = await fetch(url);
console.log(response.headers.get('content-type');
// or
response.headers.forEach(header => console.log(header));

Answer №2

In situations like this, the response object provides access to various properties. For example, to access the url property, you can simply use response.url.

fetch({someURL}, {
 method: "POST"
}).then((response) => response).then((result) => {return result.url});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prisma Hack: excluding properties in type generation

EDIT hiding fields in the TypeScript definitions may pose a hidden danger: inaccessible fields during development with intellisense, but accidentally sending the full object with "hidden" fields in a response could potentially expose sensitive data. While ...

What advantages can be gained from having multiple package.json files within a single application?

Embarking on the journey of creating my inaugural full react web application entirely from scratch. Previously, I've mainly worked on assignments that were partially pre-made for me. While setting up my project, I couldn't help but notice that I ...

Using the typeof operator to test a Typescript array being passed as an object

I have a puzzling query about this particular code snippet. It goes like this: export function parseSomething(someList: string[]): string[] { someList.forEach((someField: string) => { console.log(typeof someField) }) Despite passing a s ...

Enhance your SVG path by allowing users to drag points on Quadratic or Cubic Bezier curves

In my project, I am trying to make it so that when a user drags the point, it always stays aligned with the path. The goal is for the command Q, C, or S to adjust the curve based on the position of this draggable point, rather than treating it as a control ...

Getting the URL path within getStaticPaths in Next.js

Is there a way to retrieve the last number from the current URL pathnames in getStaticPaths? http://localhost:3000/category/food/2 -> 2, http://localhost:3000/category/food/3 -> 3, ... I have attempted: export const getStaticPaths: GetStaticPaths = ...

Retrieve information from the pouchdb database

After successfully storing data in PouchDB, I'm wondering how to retrieve this information and display it in HTML using AngularJS. var db = new PouchDB('infoDB'); function getData(){ $.getJSON('test.json', function(data) { ...

Attaching identical class and event handlers to numerous dynamically created elements

I am facing a challenge with the following HTML structure: <a href="#" @click.prevent="toggleClass">Show/Hide</a><br> <li :class="{myClass: showItems}">Item 1</li> <a href="#" @click.prevent="toggleClass">Show/Hide< ...

Retrieving information from a JSON output to use in an insert statement in Python

Imagine a scenario where I have a JSON structure as follows: [ { "randomcol" : "randomvarchar" } ] This JSON is generated through the following code snippet: cursor_orcl.execute(""" Select * from test_t where """) r ...

Combining the redux toolkit function createAsyncThunk with Angular's HttpClient by leveraging the ApiService

Currently, I am working on incorporating @reduxjs/toolkit into an Angular project. Is there a way to pass an Angular service as a parameter to the callback of createAsyncThunk instead of utilizing fetch directly? I referenced the documentation for an exa ...

What is the threading model utilized by node.js?

Upon establishing a connection with a server operating on node.js, how is the connection handled? Is it one connection per process? Does it follow a connection per thread model? Or does it operate based on request per thread? Alternatively, does it use ...

Ways to retrieve data object within an HTMLElement without relying on jQuery

Within my web application, I have successfully linked a jQuery keyboard to a textbox. Now, I am seeking a way to explicitly call the keyboard.close() function on the keyboard as I am removing all eventListeners from the text field early on. To achieve thi ...

Having difficulty transitioning Express Controller logic to a Service Class

Within the User Controller, there is a function that processes a GET request to /user/ and retrieves two JSON objects randomly from a MongoDB collection. Here is how the response looks like inside the controller: [{ "name": "User 1" ...

Creating a reusable field for reactive forms in Angular: A step-by-step guide

I need assistance with creating a versatile field component for reactive forms, but I am facing challenges in retrieving the value from the custom-input element. <form [formGroup]="form" (ngSubmit)="submit()"> <custom-input i ...

The $scope variable does not sync with the express API

I have noticed that the static part of my app is loading fine. Recently, I integrated a service using Express as a simple API. However, when I attempt to set the #scope from my module's controller, it seems like it hasn't loaded at all. I am puzz ...

Attempting to iterate through a Query each loop for the Raphael object

I'm currently facing a challenge with creating a jQuery .each() function to iterate through an array that I've constructed from a Raphael object. While I am able to achieve this using a traditional JavaScript for-loop: for (var i = 0; i < reg ...

Issue with JavaScript: Flag set to false does not halt the simple animation

My goal is to initiate animations when the mouse is pressed down and then immediately halt them once the mouse is released. Upon pressing the mouse, I set a flag to true which triggers the animation of the corresponding button that was clicked. However, t ...

What are the steps to implementing React in this particular situation?

In my Django application, there is a view that presents booking data for all theaters on a specific date. Once the data is loaded, an authorized user can carry out tasks such as assigning coordinators or changing timings using ajax (jquery) and updating ...

The mousedown event handler in Three.js disrupts the focus on the input field

Here is a line of code in threejs: document.addEventListener('mousedown', onDocumentMouseDown, false); This particular code snippet causes the input field to lose focus when clicked. This can be problematic, for instance, when there is a canva ...

Displaying a loading spinner image as PHP script runs

Hey there! I've been experimenting with using a script to show a loading bar while my PHP code is running. I followed the instructions on this website, but even after following the exact steps, my loading bar still isn't showing up. Any suggestio ...

Getting a list of values from a JsonArray using C# is a breeze with these simple steps

Here is the Json string provided (cannot be modified as it comes from an external source) { "IsValid": true, "Result": [ { "PartNumber": "ABC", "Id": "x123" }, { " ...