Axios library
16.08.2024
13
0
0
0
It is a promise-based HTTP Client for node.js and the browser. It is isomorphic (= it can run in the browser and nodejs with the same codebase). On the server-side it uses the native node.js http module, while on the client (browser) it uses XMLHttpRequests.
Features
- Make XMLHttpRequests from the browser
- Make http requests from node.js
- Supports the Promise API
- Intercept request and response
- Transform request and response data
- Cancel requests
- Timeouts
- Query parameters serialization with support for nested entries
- Automatic request body serialization to:
- JSON (application/json)
- Multipart / FormData (multipart/form-data)
- URL encoded form (application/x-www-form-urlencoded)
- Posting HTML forms as JSON
- Automatic JSON data handling in response
- Progress capturing for browsers and node.js with extra info (speed rate, remaining time)
- Setting bandwidth limits for node.js
- Compatible with spec-compliant FormData and Blob (including node.js)
- Client side support for protecting against XSRF
Example of a GET request
axios.get('/api/results/')
.then(response => {
setItemsData(response.data); // Save the data in state
})
.catch(error => {
console.error('There was an error fetching the data!', error);
});
Example of a POST request
axios.post('/api/results/', form_data)
.then(data => {
console.log('Success:', data);
setUpdateTrigger(true)
})
.catch(error => {
console.error('Error:', error);
});
Example of a PUT request
axios.put(`/api/results/${form_el.target.id}/`, form_data)
.then(data => {
console.log('Success:', data);
setUpdateTrigger(true)
})
.catch(error => {
console.error('Error:', error);
});
Example of a DELETE request
axios.delete(`/api/results/${item.id}/`)
.then((res) => setUpdateTrigger(true));
Used in
In this article you will understand how to add a web tutorial on a website for guests using React components. With the ability to define to which elements hints will be linked and how many such links must exist, it β¦
I will be busy developing a new project. His name is SearchResultParser. Its essence is to parse data from the search results of various search engines, such as google, youtube, yandex and others.
In this article, I will describe in detail how I solved the problem of server response delays to client requests. I will describe the operation of the ERR_HTTP2_PING_FAILED error and what steps I took to identify the problem.
In this article, I will describe a process of integrating the <b>React</b> framework into the Django website. We will configure a communication API between both of them. Also, a TailwindCSS library will be installed.
In this article, you will know the way to integrate the React framework into a Django project. As a result, you will get a full-stack app/website. Also in the article, you can find video-tutorial and downloadable samples for personal studies.