Guide to stripping HTTP headers from a REST API request using JavaScript

Hey there! I'm currently working on extracting a specific part of the response from the {}. This information is retrieved from the gemini public database, and my goal is to retrieve only the content within the curly braces and store it as a string in a database.

const gemini = async() =>{
    var burl = 'https://api.sandbox.gemini.com'
    var query = '/v1/pubticker/'+'ethusd'
    var url = burl + query
    var smth = fetch(url)
    delete smth.vary
    return smth

}

export default gemini

Below is the response that I receive:

status: 200 OK
    content-length: 133
    content-type: application/json
    date: Mon, 08 Nov 2021 18:03:09 GMT
    server: nginx
    vary: Origin

{"bid":"4786.52","ask":"4787.78","volume":{"ETH":"8232.886562","USD":"38693689.50955448","timestamp":1636394400000},"last":"4786.83"}

This is the specific portion I want to isolate:

{"ETH":"8232.886562","USD":"38693689.50955448","timestamp":1636394400000},"last":"4786.83"}

Answer №1

Instead of worrying about "removing the headers", focus on extracting the necessary information from the JSON response you receive. The gemini function is designed to return a Promise after making a fetch call. You can handle this Promise just like any other fetch call, as shown below:

let response = await gemini();
let result = await response.json();

The variable result will then hold the specified object from the JSON data. It seems that you are interested in retrieving the volume and last properties from this object based on your question description.

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

Unraveling the intricacies of extracting data from nested object properties

Why do my variables stop being reactive after unwrapping from props? I have three components - a parent component, a second component for display, and a third component for updating data based on input (simplified code here). The third component updates ...

Having trouble displaying values from nested JSON in a datatable

Response from server : ["{\"CLIENT\":[{\"tranche\":\"1-4\",\"prix\":\"65.96\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"1-4\",\"prix\ ...

Creating a responsive image within a panel using Bootstrap

I've been struggling to make a responsive image fit inside a panel while maintaining its aspect ratio and ensuring none of it gets cut off. I've attempted various CSS tweaks with no success. My setup involves Bootstrap along with React.js using r ...

Issues with LocalStrategy not executing in passport authentication

I am currently facing an issue with authenticating using Passport and LocalStrategy. It seems like the strategy is not being called and when I log the user object in passport.authenticate, it returns "false". Below is my client-side code: logIn = () =& ...

What is the best way to modify just a portion of the state in React?

Consider the following State object: const initialState = { data: { user: '', token: '', } } In the Reducer function: case 'DO_SOMETHING': return {...state, data: action.payload } If I make a shallow copy of th ...

Tips for sharing a React component with CSS modules that is compatible with both ES Modules and CommonJs for CSS modules integration

Some frameworks, like Gatsby version 3 and above, import CSS modules as ES modules by default: import { class1, class2 } from 'styles.modules.css' // or import * as styles from 'styles.modules.css' However, other projects, such as Crea ...

What steps can be taken to avoid triggering ng-drop-success upon clicking?

Here is an example of a div with Angular directives: <div ng-drop="$ctrl.activateDropArea" ng-drop-success="$ctrl.onDropComplete($data,$event)"> However, I am facing the issue where the onDropComplete function gets called even when I click on the d ...

Dropzone ceased functioning following the transition from version "4.2.0" to "5.7.0" while utilizing jquery version "3.3.1"

Currently, I am loading my libraries in the following way: <link href="~/lib/dropzone/dropzone.min.css" rel="stylesheet" /> <script src="~/lib/dropzone/dropzone.min.js"></script> <script src="~/Scripts/jquery-3.3.1.min.js"></sc ...

When encountering an OR operator, Javascript will cease execution of the remaining conditions

This is a basic JavaScript form-validation I created. All the document.form.*.value references are present on my page, except for the document.form.dasdasdas.value ==''. In the code below, the purpose is to display an error if any of the forms a ...

What is the best way to retrieve an object from a POST request using Angular AJAX calls in a NODEJS environment?

When the button is clicked, a method will be called. The code for this is as follows: .controller('templeDetailsList', function ($scope, $http, $ionicModal) { $scope.starclick = function(){ var newFav = [{ ...

Converting a string containing multiple objects into an array with unique keys

I have a string with multiple objects and I need to add these objects into an array with different values. The data is received from the cart, so the number of objects can vary. For example: {"hidden_product_name":"productA","productId":"120","product_sk ...

Exploring the capabilities of batch updates in Firestore with the latest web version-9

I am facing issues when trying to update certain values in my firestore collection within my nuxt project. const batch = writeBatch(firestore); const data = query(collection(firestore, `notifications`, `${uid}/news`)); const querySnapshot = await ...

Animate the expansion and shrinkage of a div instantly using jQuery

I am trying to create an animation effect using jQuery animate on a div element where it starts large and then becomes smaller. Here is the code I have written: $(this).animate({ opacity: 0, top: "-=100", width: "38px", height: "32px" }, 1 ...

Generating JSON output with PHP

Below is the current progress : if (is_request_var('requestor') == 'PPA'){ $dataJson[][] = array("status" => "success","value" => $fetchValue ,"postcode" => $fetchPostCode,"params"=>""); $notice = $dataJson; } I a ...

Tips for transferring the ID from one element to another using JavaScript

I'm attempting to create a slideshow using icons all within one class. The "active" style class will have an ID and represent the current picture. By clicking either the left or right button, I aim to change the style of the active class. const l ...

The default image field value in Django Rest Framework triggers a Validation error

Our development team utilizes REST and includes a site management feature on our app. This feature retrieves information such as name, description, title, and icon from the API. Additionally, we have an admin interface on a separate front-end app that can ...

How can I include JavaScript in an HTML document?

My folder structure is as follows: Inside webapp/WEB-INF/some.jsp, I also have a javascript file located in the same directory at webapp/WEB-INF/js/myform.js. I referenced it in some.jsp like this: <script type="text/javascript" src="js/myform.js"> ...

What is the best way to retrieve a specific object from a JSON file using a Get request in a Node.js application?

My focus is on optimizing an API, which is why I'm working with only the data that's essential for my analysis. I've set up a route to extract specific objects, but I'm only interested in four of them: account_manager, fronter, closer, ...

The string array being sent to the WebService is being cut off

I created a C# WebApi method with the following signature: [HttpPost] [Route("getbyid/{date}")] public Response Get(DateTime date, [FromBody] List<string> ids) When testing this method using Postman and sending a list of strings in the body, everyt ...

Upon submitting the form, the dynamic dependent drop-down list fails to offer any available options

Hey there, I've got a form with two drop-down lists: id="dd-1" & id="dd-2". The options in id="dd-2" are generated from the database based on what's selected in id="dd-1"; I'm using onChange=getChildOf(this.value) in id="dd-1" for this ...