2016-10-27 12 views

Odpowiedz

8

Oto przykład pobrania POST. Możesz zrobić to samo dla DELETE :)

function createNewProfile(profile) { 
    const formData = new FormData(); 
    formData.append('first_name', profile.firstName); 
    formData.append('last_name', profile.lastName); 
    formData.append('email', profile.email); 
    return fetch('http://example.com/api/v1/registration', { 
     method: 'POST', 
     body: formData 
    }) 
    .then(response => response.json()) 
} 

createNewProfile(profile) 
    .then((json) => { 
     // handle success 
    }) 
    .catch(error => error); 
+0

Więc POST, PUT i DELETE mają identyczną składnię? –

+0

Powinno działać. – FlatLander

+1

Różnica polega na tym, że będziesz potrzebować "id" rekordu do USUŃ lub PUT. Będzie wyglądać teraz jak: 'return fetch ('http://example.com/api/v1/registration/1', {' 'method: 'PUT',' 'body: formData' '}) ' – Hanmaslah

Powiązane problemy