axios post await

axios,web_developer,http,api,promise,await

Axios là một HTTP client được viết dựa trên Promises được dùng để hỗ trợ cho việc xây dựng các ứng dụng API từ đơn giản đến phức tạp. Có thể sử axios để post, get, put, delete...

Tips: Tìm hiểu sâu về axios

Post request

const newPost = {
    userId: 1,
    title: 'A new post',
    body: 'This is the body of the new post'
}
const sendPostRequest = async () => {
    try {
        const resp = await axios.post('https://jsonplaceholder.typicode.com/posts', newPost);
        console.log(resp.data);
    } catch (err) {
        // Handle Error Here
        console.error(err);
    }
}
sendPostRequest();

Có thể bạn đã miss một số snippets code

await axios get

await axios get

axios post await

Axios là một HTTP client được viết dựa trên Promises được dùng để hỗ trợ cho việc xây dựng các ứng dụng API từ đơn giản đến phức tạp. Có thể sử axios để post, get, put, delete...

using Typescript callback style error handling

using javascript callback style error handling

Sử dụng Promise.all với fetch

Sử dụng Promise.all hiệu quả sẽ làm cho hiệu suất của code chúng ta tăng lên đáng kể. Và mã sau đây giúp các bạn có thể get được nhiều data mà không ảnh hưởng tới performance.