简体   繁体   中英

How to create an patch request with axios

axios.post('/api/v1/users',
            { "edited_field": "email", "email": email },
            { headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': crsfToken }, }
        ).then((response) => {
            // Code
        }).catch((error) => {
            // Code
        })

I have this post method, but i want to create an patch method of this. i have seen some solutions where they post a form with an input value='patch' but since im not using a form i have no idea how it must be done.

Any help is welcome:D

Thanks in advance!

Axios has a built-in patch method. You can modify the code you currently have by replacing axios.post with axios.patch

axios.patch('/api/v1/users',
            { "edited_field": "email", "email": email },
            { headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': crsfToken }, }
        ).then((response) => {
            // Code
        }).catch((error) => {
            // Code
        })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM