Skip to content

Request Functions ​

TIP

The examples below use get and post, but options, head, delete, patch, and put are also supported.

GET ​

JSON (default) ​

ts
// axle
const data = await axle.get('/url', { id: 1 })

// axios
const { data } = await axios.get('/url', { params: { id: 1 } })

Blob ​

ts
// axle
const blob = await axle.getBlob('/url', { id: 1 })

// axios
const { data } = await axios.get('/url', {
  params: { id: 1 },
  responseType: 'blob',
})

Text ​

ts
// axle
const text = await axle.getText('/url', { id: 1 })

// axios
const { data } = await axios.get('/url', {
  params: { id: 1 },
  responseType: 'text',
})

Document ​

ts
// axle
const doc = await axle.getDocument('/url', { id: 1 })

// axios
const { data } = await axios.get('/url', {
  params: { id: 1 },
  responseType: 'document',
})

ArrayBuffer ​

ts
// axle
const buffer = await axle.getArrayBuffer('/url', { id: 1 })

// axios
const { data } = await axios.get('/url', {
  params: { id: 1 },
  responseType: 'arraybuffer',
})

Stream ​

ts
// axle
const stream = await axle.getStream('/url', { id: 1 })

// axios
const { data } = await axios.get('/url', {
  params: { id: 1 },
  responseType: 'stream',
})

POST ​

JSON (default) ​

ts
// axle
const data = await axle.post('/url', { name: 'foo' })

// axios
const { data } = await axios.post('/url', { name: 'foo' })

application/x-www-form-urlencoded ​

ts
// axle
const data = await axle.postUrlEncode('/url', { name: 'foo' })

// axios
const { data } = await axios.post('/url', qs.stringify({ name: 'foo' }), {
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})

multipart/form-data ​

ts
// axle
const data = await axle.postMultipart('/url', {
  name: 'foo',
  file: new File(),
})

// axios
const formData = new FormData()
formData.append('name', 'foo')
formData.append('file', new File())

const { data } = await axios.post('/url', formData, {
  headers: { 'Content-Type': 'multipart/form-data' },
})