Post

Axios RestAPI 호출

1. Axios

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import axios from 'axios';

function get() {
    axios.get('http://localhost:8080/get?title=foo&id=1')
        .then(response => {
            console.log("GET Response:", response.data);
        })
        .catch(error => {
            console.error("GET Error:", error);
        });
}

function post() {
    axios.post('http://localhost:8080/post', {
        title: 'foo',
        body: 'bar',
        userId: 1,
    })
        .then(response => {
            console.log("POST Response:", response.data);
        })
        .catch(error => {
            console.error("POST Error:", error);
        });
}

function put() {
    axios.put('http://localhost:8080/put', {
        id: 1,
        title: 'updated title',
        body: 'updated body',
    })
        .then(response => {
            console.log("PUT Response:", response.data);
        })
        .catch(error => {
            console.error("PUT Error:", error);
        });
}

function del() {
    axios.delete('http://localhost:8080/delete/1')
        .then(response => {
            console.log("DELETE Response:", response.data);
        })
        .catch(error => {
            console.error("DELETE Error:", error);
        });
}
This post is licensed under CC BY 4.0 by the author.