Quiero enviar varias solicitudes PUT en un solo método, pero no sé si es posible, porque toda la documentación y las respuestas en SO son solo para solicitudes GET.
// vue script, this is one PUT request updateProduct() { const config = { headers: { Authorization: `Bearer ${localStorage.getItem("token")}` }, }; axios .put( "myapihere.com" + this.$route.params.id, { name: this.name, }, config ) .then(async (res) => { console.log(res); }) .catch((err) => { console.log(err); }); }, Quiero agregar 2 solicitudes PUT más en el método updateProduct . ¿Es posible usar Promise.all? y luego, ¿cómo envío el cuerpo a cada URL correspondiente? Agradezco toda ayuda, gracias.
// vue script, this is one PUT request updateProduct() { const config = { headers: { Authorization: `Bearer ${localStorage.getItem("token")}`, "Content-Type": "application/json" }, }; // lets say you wanna use the following data to send to 3 requests const allNames = ["name1", "name2", "name3"]; // following lets say your url params that are corresponding to your eachrequests const allParamIds = ["11","12","13"] const allRequests = allNames.map((eachName, index) => { const currentName = eachName; const currentParamId = allParamsIds[index] const currentUrl = `myapihere.com/${currentParamId}` // you have to return as a promise return axios.put(currentUrl, body: JSON.stringify({name: currentName}), config) }) // Promise.all() takes an array as argument, allRequests is an array Promise.all(allRequests) .then((response) => { // response will be an array console.log("response is", response); }) .catch(err => console.error(err)) },¡Avísame si te funcionó o no!