“buscar API em JS” Respostas de código

buscar javascript API

fetch('http://example.com/songs')
	.then(response => response.json())
	.then(data => console.log(data))
	.catch(err => console.error(err));
Bewildered Booby

buscar js

const data = { username: 'example' };

fetch('https://example.com/profile', {
  method: 'POST', // or 'PUT'
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
  console.log('Success:', data);
})
.catch((error) => {
  console.error('Error:', error);
});
Lively Ladybird

buscar javascript API

fetch('http://example.com/movies.json')
  .then((response) => {
    return response.json();
  })
  .then((myJson) => {
    console.log(myJson);
  });
Gleaming Gemsbok

buscar

//Obj of data to send in future like a dummyDb
const data = { username: 'example' };

//POST request with body equal on data in JSON format
fetch('https://example.com/profile', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then((response) => response.json())
//Then with the data from the response in JSON...
.then((data) => {
  console.log('Success:', data);
})
//Then with the error genereted...
.catch((error) => {
  console.error('Error:', error);
});

//
Creepy Gábor

buscar API em JS

// fetch API
var myData = async () => {
    try {
       const raw_response = await fetch("https://jsonplaceholder.typicode.com/users");
       if (!raw_response.ok) { // check for the 404 errors
           throw new Error(raw_response.status);
       }
       const json_data = await raw_response.json();
          console.log(json_data);
       }
       catch (error) { // catch block for network errors
            console.log(error); 
        }
}
fetchUsers();
Outlander

buscar

const options = {method: 'GET', headers: {Accept: 'application/json'}};

fetch('https://api.test.com/data/id', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
ofroog

Respostas semelhantes a “buscar API em JS”

Perguntas semelhantes a “buscar API em JS”

Mais respostas relacionadas para “buscar API em JS” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código