API
Swizzle provides an API wrapper that's already connected to your backend and automatically injects authentication information for you.
Use the API
Import the API wrapper at the top of your file.
import api from "../Api";
Then use api as you would axios. Asynchronous example:
//asynchronous GET
const response = await api.get("/")
console.log("Status", response.status)
console.log("Data", response.data)
Synchronous example:
api.post("/sendData", {"data": "to send"}).then((response) => {
console.log("Data", response.data)
}).catch((error) => {
console.error("Error", error)
})
Last updated