[removed] Fetch DELETE and PUT requests

前端 未结 7 2079
一个人的身影
一个人的身影 2020-12-01 04:26

I have gotten outside of GET and POST methods with Fetch. But I couldn\'t find any good DELETE and PUT example.

So, I ask you for it. Could you give a good example

7条回答
  •  感情败类
    2020-12-01 04:59

    Here is a fetch POST example. You can do the same for 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);
    

提交回复
热议问题