I am new to using API’s. I’ve been trying to use this API called Carbon Interface. it supposed to give an estimate of your carbon footprint based on how much electricity you use. I created this quick project to test it but whenever I try to use it I get error code 401, I look it up and it’s Unauthorized
Tag: fetch
Get a response in chunks from express in browser
I’m building a progress bar for some long-running server-side tasks (up to a few minutes), and I’d like a way to display the progress of the task. I could use WebSockets or poll on intervals, but I don’t want to keep track of each task. Instead, I’d like to use long-polling and write progress updates to the stream. Here is
How to resolve CORS error in Fetch API js
I want to fetch json from my subdomain (File Hosting Server) , but it gets the following error: Reason: CORS request did not succeed) (Reason: CORS header ‘Access-Control-Allow-Origin’ missing my similar code: I add but don’t work. I add to code, fetch file but return response status 0 , mode: ‘opaque’. please help me. Answer CORS is configured through server-side,
console logging prints a promise when function returns an object but prints the data when it is not an object
I have this function that makes a get request to an api When I use this function on a buttons onClick handler The console shows an a promise not the actual data but when I switch my get function to where it isn’t returning an object around the data, then access the data by the console prints out the actual
Progress for a fetch blob javascript
I’m trying to do a javascript fetch to grab a video file using fetch. I am able to get the file downloaded and get the blob URL, but I can’t seem to get the progress while its downloading. I tried this: The problem is that I get “Response.blob: Body has already been consumed”. I see that the reader.read() is probably
mock post method npm request module with jest
I know that npm request module is now deprecated, but i want to mock a post http call with jest. Here is my function And in try this in my test : But it returns TypeError: Cannot set property ‘post’ of undefined I want to mock that method to handle error and response to test methods inside them Answer Use
Can’t Post JSON with Javascript ‘fetch’ in React Native?
I’m currently working on a really simple project. When I tried to console log req.body it gives me empty object. app.js (React Native) server.js (Node JS Backend API) Answer You should parse the incoming requests with JSON payloads. In server.js add the middleware fucntion:
How to populate array with values from API using “fetch” in javascript function
I’m trying to write a function that builds an array where each value of the array is a value pulled from an API using a unique url, once the value is fetched from the API it is pushed into the existing array. Basically when the function is called I want to populate an array with fetched API data for each
Cannot destructure an object
I fetched and object which contains two properties, one is a number and one is an array. So I right away accessed the array and then assigned to a state and then passed each item to another component through context api. And it does not working. Here is my code: In this code ‘correct_answer’ is a string and ‘incorrect_answers’ is
How do I use an API in Discord.js?
I was looking for a cool way I could automate some interesting news articles on my discord server. I wanted to use webhooks at first but then decided to go with APIs. I looked all around and saw that I should go with New York Times API but when I went to code it, it came up with a few