Skip to content

Latest commit

 

History

History
101 lines (72 loc) · 4.03 KB

File metadata and controls

101 lines (72 loc) · 4.03 KB

> Back to homepage

Migration guides

You may think it's too hard to switch, but it's really not. 🦄

Axios

Axios is very similar to Got. The difference is that Axios targets browsers first, while Got fully makes use of Node.js features.

Common options

These options remain the same as well:

Renamed options

We deeply care about readability, so we renamed these options:

Changes in behavior

  • transformRequesthooks.beforeRequest
    • The API is different.
  • transformResponsehooks.afterResponse
    • The API is different.
  • baseUrlprefixUrl
    • The prefixUrl is always prepended to the url.
  • timeout
    • This option is now an object. You can now set timeouts on particular events!
  • responseType
    • Accepts 'text', 'json' or 'buffer'.

Breaking changes

  • onUploadProgress
  • onDownloadProgress
  • maxContentLength
    • This option does not exist. Instead, use a handler.
  • validateStatus
    • This option does not exist. Got automatically validates the status according to the specification.
  • proxy
    • This option does not exist. You need to pass an agent instead.
  • cancelToken
    • This option does not exist, but will be implemented soon. For now, use promise.cancel() or stream.destroy().
  • paramsSerializer
    • This option does not exist.
  • maxBodyLength
    • This option does not exist.

Response

The response object is different as well:

The response.headers object remains the same.

Interceptors

Got offers hooks instead, which are more flexible.

Errors

Errors look the same, with the difference error.request returns a Got stream. Furthermore, Got provides more details to make debugging easier.

Cancelation

While Got doesn't support AbortController yet, you can use promise.cancel().

Convenience methods

Convenience methods, such as axios.get(…) etc. remain the same: got.get(…). Instead of axios.create(…) use got.extend(…).

You're good to go!

Well, you have already come this far 🎉
Take a look at the documentation. It's worth the time to read it.
There are some great tips.

If something is unclear or doesn't work as it should, don't hesitate to open an issue.