Questions tagged [fetch-api]

1

votes
1

answer
429

Views

Fetch : status 302 in Edge 17

I'm using js fetch API to retreive datas from JSON. It's working fine (even in IE 11), except in Edge 17 i get 302, the response header are : Content-length : 0 Content-type: text/plain; charset=utf-8 Location: http://local.mysite.com/xxx My local website is on a Mac, i'm using BrowserSync to make i...
Julien CHAZAL
2

votes
1

answer
19

Views

Images not populating when using Unsplash API

I am learning how to use fetch APIs and I can't seem to figure out why only 1 image is showing up when using the Unsplash API. I think it has something to do with map, but I'm not sure. Any help our guidance is appreciated. document.getElementById('search').addEventListener('click', () => { const se...
KristenRen1
1

votes
1

answer
1.3k

Views

Is it possible to download an audio file and play it using React Native Expo?

I have audio files hosted on a server that I'd like my app to access after authenticating. Users send a GET request which includes an authentication token, and the server returns the binary audio data. As far as I can see there is no way to save this 'blob' as an audio file to the filesystem. The cu...
Tom
1

votes
1

answer
546

Views

Accessing resolved promise object properties

I'm having trouble accessing resolved promise object properties. Using fetch, I have a .then doing this: .then((response) => console.log(response.json())) I'm trying to access the user property of the response object by doing this: .then((response) => console.log(response.json().user)) and it's retu...
Chris Wingler
1

votes
4

answer
55

Views

ReactJs : How to prevent componentWillUpdate from re-rendering multiple times

I am creating a simple Todo App, I am using componentDidMount to display the data from the database. But the problem is, Once I add a new data the data gets stored but it doesn't display on to the page unless I refresh it. Then I came across componentDidUpdate. It works perfectly, But it re-renders...
bharathi
0

votes
1

answer
19

Views

How to handle fetch errors?

I know there is a lot of questions about fetch erros, but it seems that no one is of any help to me. Every site or documentation say that fetch doesn't throw on errors, but that doesn't seem to be correct. What happens is that 404 errors, for example, throws on console but then goes for the then ca...
Yerko Palma
1

votes
0

answer
185

Views

How Do I Set State with External Function in React (And Should I?)

I have an API fetch request that I'd like to use in 2 different places on 2 different sets of data. I tried to implement the answer from user, aeid, on this post but it is not working. I know that I can successfully update the state if I nest the fetch request within my components, but I don't want...
Jessie Richardson
1

votes
0

answer
1k

Views

Empty request body when using fetch

I'm trying to make graphql calls from a React component to a PHP server, using fetch. It is the first time I try using fetch. I'm using React JS on browser side and Symfony 4 on server side. However all of my calls end up with an empty body on server side, even though my browser dev tools seem to in...
Zephyr
1

votes
1

answer
456

Views

How to set localAddress in fetch request in node.js?

On my server i have multiple ip addresses. I need to make API call from my node.js server to external service, but i need to make it from specific ip address each time (the ip depend on many factors). it seems that HTTP module of node support localAddress property to specify from what ip address sen...
Alex
1

votes
1

answer
247

Views

How to properly handle a 400 (or any non-successful status codes) with JS fetch

I have an API endpoint (which happens to be Django Rest Framework), that will usually return a response status code 201 created, but will also return a 400 error when a field hasn't been correctly entered. I'm using fetch to consume this API and return json, as follows: export const myAPICall = (pos...
Loic Duros
1

votes
0

answer
1.2k

Views

How to fetch PDF (doc, docx) with Fetch API?

There is another of doing this except the following code ? fetch(url) .then(response => response.blob()) .then(blob => console.log(blob))
dtalaba
1

votes
1

answer
336

Views

fetch-mock calls the actual API instead of mocking the request

Given this code: const fetch = require('isomorphic-fetch') module.exports = function suggestions (...args) { // some error handling code return fetch(MY_ENDPOINT) } I have found that when using fetch-mock like this: require('isomorphic-fetch') const fetchMock = require('fetch-mock/es5/server') fetch...
vamsiampolu
1

votes
0

answer
97

Views

Selenium Webdriver error related to the Windows.Fetch for the login

I'm trying to login by building up the URL using the following: Chrome Login: URL = 'https://' + Username + ':' + Password + '@' + TestShortURL; driver.Navigate().GoToUrl(URL); On of the application Pop-ups an error is being displayed: Error getting experiment details from server: TypeError: Failed...
King81
1

votes
1

answer
177

Views

Geoserver WFS fetch CORS not working

I am trying to do a wfs request to an external geoserver. Setting mode: no-cors works but I want to parse the result directly which is then not possbile.. fetch(this.selectedLayer.url + '/wfs', { method: 'POST', Origin: 'anonymous', body: new XMLSerializer().serializeToString(this.wfs) }) How to tel...
Dennis Ich
1

votes
1

answer
3.7k

Views

Search functionality and fetch api in React

I'm working on an app that makes a call to Unsplash's API and displays the response. I was able to get/display the response easily with just the /photos endpoint when I had the fetch request in the componentDidMount(), but I want to make the app searchable, so I added performSearch() with a default...
Bianca M
1

votes
1

answer
166

Views

TypeError with async/await and express routing

Relative beginner here, I'm having issues with express and async/await functions, with an unhandled promise rejection. Here is my code on the client side, grabbing username and password from a page and sending it over. async function signIn() { let username = document.getElementById('username').valu...
woofdinos
1

votes
2

answer
95

Views

How to delay fetch() until website has finished loading dynamic content

I have a chrome extension. Whenever the user clicks the extension's button it will download the source of the following URL: 'smmry.com/(the user's current active tab's url)' I'm using the following javascript code to download the source of the URL in the form of a html file. This code is currently...
Roymunson
1

votes
1

answer
380

Views

Fetch request with retry parameter

I am using fetch API and try to implement a function which gets retry parameter and re-sends another request if the previous one was failed. I've found this answer and here is my code, Does anybody know how to write the function in none-recursion? const fetchRetry = (url, delay, limit, fetchOptions...
Andy
1

votes
0

answer
98

Views

Isomorphic fetch do not pass file when credentials are set to 'same-origin'

I am using isomorphic fetch and using Formdata. When I am trying to post/ request formdata using isomorphic-fetch-api, there are two cases which is kind of unexpected behaviour as respect to the docs. (Note: formdata here includes file object) When adding credentials: include, then the request is pa...
Reck
1

votes
0

answer
23

Views

Why doesn't redux saga continue after fetch promise resolves?

I have a request function that returns a promise. response.json(). My Issue is that although it resolves, but my loadData function does not continue past my call. export function* loadData() { console.log('Saga: Loading Data...'); try { const response = yield call(request, requestURL, { method: 'GET...
Danny
1

votes
1

answer
22

Views

How to cleanly handle an expected error in fetch?

I need to query some data via a fetch() call but I am never sure whether the request will be successful, HTTP-wise: while the server is up, the URL may (legitimely) hit a non-existing page. I would like to cleanly handle the case and my current approach is by raising an exception: // the URL is just...
WoJ
1

votes
0

answer
192

Views

React+Redux+Asynch: data loading cascade, start the following after the previous complete

Having not much experience in ReactJS currently trying to solve components cascade loading. Let me explain use case on an example. Assume we have 3 comboboxes - Author, Book, Library. Something triggers loading Author data -> When data is loaded, the first found author is automatically selected and...
Triple
1

votes
1

answer
43

Views

React Native Fetch API returning old data

my fetch API always returns the old json data. My app requests API for my user list, it works in the beginning, however when I post a new user, and refresh my list (call the same fetch function), it returned the same list (without new user). But it works whenever I totally close my apps, and re-open...
hallz12
1

votes
2

answer
100

Views

React Native Posting/Fetching to Backend

I am having trouble posting data to an express backend with React Native via Android Emulator. The goal of the app is to allow customers to post microtask requests like home chores and lawn care where all the data will be stored to a AWS RDS MySQL Server. On the flip side there are freelancers who c...
Solomon Antoine
1

votes
0

answer
530

Views

Cannot get response header with fetch api with cross domain request in react app

I am using passport cookie-based authentication on my server side when I request from my react client I get the response as expected with successfully authentication with authentication cookie in browser debug I can view it too but the cookie is now accessible in react app where my login service is...
1

votes
0

answer
49

Views

fetch request not sending cookies to PHP server

I am having a weird problem where when I make a fetch request from the client in development it is not sending the cookies to my server (legacy server that does not run on localhost). Here is my code for the fetch request: get( url ) { return fetch(`${API_URL}${url}`, { method: 'GET', headers: heade...
M Hornbacher
1

votes
0

answer
449

Views

Javascript fetch api posted file to C# controller

I am trying to use newer Fetch api to Post File collection to backend C# . let postFilesTask = fetch('/Home/Upload', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'multipart/form-data' }, body: formData }) formData is formed as following in typescript: var acp_file...
Manotosh sil
1

votes
0

answer
384

Views

Vue axios (and fetch) responses not passing into data property

I have a Vue (2.2.1) component that should display a membership directory by making a request to a Laravel API. The request succeeds, and the response is correct when I console.log it. Likewise, the API request succeeds in Postman and the JSON object is correctly formatted. But, the response won't p...
Anthony Watson
1

votes
0

answer
39

Views

Fetch large file and automatically resume on network error (rather than starting all over again)

I'm wondering if it's possible to use the JavaScript fetch API to download a very large file in bad network conditions? I'm downloading a large file as a stream an 'consuming' it on-the-fly with response.body.getReader(), but since the file is so big (many gigabytes), there's inevitably a network er...
1

votes
0

answer
570

Views

Upload local file with fetch / content-type: octet-stream

I am currently developing a Sketch Plugin, where an image gets sent to the Microsoft Custom Vision API for object detection. The Sketch Plugin itself is written in Javascript, a fs polyfill and a fetch polyfill is available. An API call with an image url works perfectly fine. However, I have trouble...
lottemacchiato
1

votes
1

answer
132

Views

Spotify API, can't chain two API calls properly

I'm having trouble chaining these two API calls. So basically I'm trying to recreate the Spotify interface and individually, these calls actually work which is great! I also have an 'onPlayClick' function that's basically the same function as 'onNextClick' as seen below, but with a different endpoi...
user3026715
1

votes
0

answer
33

Views

Make a GET request to Yesmail using JavaScript

I'm trying to make a GET request to the Yesmail API and return the data associated to a email marketing campaign based on a message ID that right now is hard coded but would eventually be passed. Right now I keep getting a 401 (Unauthenticated). I have been using the 'Sample Request Header' but I'm...
nathan.brunetti
1

votes
2

answer
298

Views

Get value from array inside fetch result (React.js)

I need to acess a name that is inside the array area_set that is inside a result from an API fetch. I try multiple ways but is says or that map is undefinedor something else. Here's the imagem of the json response: Here's my code to ask for the json: componentDidMount() { fetch(url + '/couch-model...
soalrib
1

votes
1

answer
247

Views

Improving performance of multiple FETCH requests in Javascript

I'm trying to improve the performance of a website which uses multiple (>20) Javascript FETCH requests to fetch data from a PHP server. The problem is that most of the requests stall for some time before they are sent to the server. I've read on the web that Google Chrome, which I'm using for access...
1

votes
1

answer
137

Views

Fetch API inside Service Worker fails only for the home page. When reloading it serves the cached offline page

I've been fighting with this for a few months now and cannot figure it out. I've been using a service worker for a while now without issue but recently I would load my website's homepage and then do a simple refresh and I would be served the offline page (and if I remove the offline page from the ca...
GreatBlakes
1

votes
1

answer
43

Views

TypeError: records.map is not a function - First React project, stuck on this error with API

I've been trying to fetch data from this local gov API https://data.qld.gov.au/api/action/datastore_search?offset=370&resource_id=2bbef99e-9974-49b9-a316-57402b00609c&q=Mooloolaba I've managed to get example API data to load into my project but when I go to use this API I run into errors, I think it...
Jackson Poultney
1

votes
2

answer
421

Views

Axios, fetch() setting request headers into Access-Control-Request-Headers instead of separate headers

I am trying to make a GET request with some custom headers from a react application. This is the code for the axios interceptor: addCaptchaHeaders(captcha, sgn, exp) { // remove the old captcha headers if (this.captchaHeadersInterceptor !== undefined) { this.removeCaptchaHeader(); } // Sign new capt...
Miha Šušteršič
1

votes
0

answer
644

Views

Response for preflight does not have HTTP ok status - Fetch API

I have a very similar issue to a number of the other posts on SO. However, I have to use authentication (using a token and tenant id) in the headers. No problems experienced when I submit a POST request, but when I submit a PATCH request, I get errors: THIS CODE WORKS FINE var urlStep2 = 'https://...
Stephan Du Toit
1

votes
0

answer
533

Views

Fetch API; why use the “no-cors” mode if the response is Opaque?

I read this question and this question . The former only explains 'no-cors' vs 'same-origin'; the latter recommends that 'no-cors' is not useful because of the Opaque Response (which Javascript cannot read/do anything useful with): You basically never ever want to use mode: 'no-cors' in practice ...
The Red Pea
1

votes
0

answer
569

Views

CORS request with Electron

I can't manage to make a CORS request from my electron app. I have set the required webSecurity mainWindow = new BrowserWindow({ width: 1024, height: 768, show: false, webPreferences: { webSecurity: false } }); then trying to get data from zoho servers fetch('https://books.zoho.com/api/v3/contacts\...
somerandomusername

View additional questions