HTTP Requests with Axios
Make GET and POST requests to APIs with Axios.
HTTP Requests with Axios is a free Vue Academy lesson on CoddyKit. This is lesson 1 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 3 lessons in total.
Talking to APIs
Most real apps load data from a backend over HTTP. While the browser has a built-in fetch, many Vue projects use Axios, a popular promise-based HTTP client with a friendlier API, automatic JSON parsing, and powerful configuration options.
Installing Axios
Add Axios to your project with your package manager, then import it where you need it.
npm install axiosImporting Axios
Import the default export to start making requests.
import axios from "axios"A GET Request
Use axios.get to fetch data. It returns a promise that resolves to a response object; the body is on response.data, already parsed from JSON.
axios.get("https://api.example.com/users")
.then(response => {
console.log(response.data)
})A POST Request
Use axios.post to send data. The second argument is the request body, which Axios serializes to JSON automatically.
axios.post("https://api.example.com/users", {
name: "Grace",
email: "grace@example.com"
})Using async/await
Promises read more clearly with async/await. Mark the function async and await the request.
async function loadUsers() {
const response = await axios.get("/api/users")
return response.data
}Inside a Vue Method
A common pattern is to call Axios from a component method and store the result in reactive data.
export default {
data() {
return { users: [] }
},
methods: {
async fetchUsers() {
const res = await axios.get("/api/users")
this.users = res.data
}
}
}Request Config: Query Params
Pass a params object to add query string parameters. Axios builds the URL for you.
axios.get("/api/users", {
params: { page: 2, limit: 10 }
})
// requests /api/users?page=2&limit=10Request Config: Headers
Send custom headers, such as an authorization token, through the config object.
axios.get("/api/profile", {
headers: {
Authorization: "Bearer " + token
}
})Base URL Configuration
Repeating the full URL everywhere is error-prone. Create an Axios instance with a baseURL and shared defaults, then use it throughout your app.
import axios from "axios"
export const api = axios.create({
baseURL: "https://api.example.com",
timeout: 5000,
headers: { "Content-Type": "application/json" }
})
// elsewhere: api.get("/users")Other HTTP Methods
Axios mirrors the common HTTP verbs: get, post, put, patch, and delete. Use the one that matches the action you want to perform.
api.put("/users/1", { name: "Updated" })
api.patch("/users/1", { name: "Patched" })
api.delete("/users/1")Quick Check
Test your knowledge of Axios requests.
Recap
Axios is a promise-based HTTP client. Use get, post, put, patch, and delete, pass params and headers through the config object, and prefer async/await for readability. A shared instance via axios.create with a baseURL keeps requests DRY. Next you will fetch data at the right point in a component lifecycle.
Learn HTML with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 42
- Lessons
- 156
Frequently Asked Questions
Is the “HTTP Requests with Axios” lesson free?
Yes — any 3 lessons of the Vue Academy learning path, including “HTTP Requests with Axios”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 3 lessons in total.
What will I learn in “HTTP Requests with Axios”?
Make GET and POST requests to APIs with Axios. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Vue Academy?
No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.
How long does the “HTTP Requests with Axios” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Vue Academy lesson?
Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- HTTP Requests with Axios
- Lifecycle Hooks and Data Fetching
- Error Handling and Global Interceptors