You may think it's too hard to switch, but it's really not. 🦄
Axios is very similar to Got. The difference is that Axios targets browsers first, while Got fully makes use of Node.js features.
These options remain the same as well:
We deeply care about readability, so we renamed these options:
httpAgent→agent.httphttpsAgent→agent.httpssocketPath→urlresponseEncoding→encodingauth.username→usernameauth.password→passworddata→body/json/formparams→searchParams
transformRequest→hooks.beforeRequest- The API is different.
transformResponse→hooks.afterResponse- The API is different.
baseUrl→prefixUrl- The
prefixUrlis always prepended to theurl.
- The
timeout- This option is now an object. You can now set timeouts on particular events!
responseType- Accepts
'text','json'or'buffer'.
- Accepts
onUploadProgress- This option does not exist. Instead, use
got(…).on('uploadProgress', …).
- This option does not exist. Instead, use
onDownloadProgress- This option does not exist. Instead, use
got(…).on('downloadProgress', …).
- This option does not exist. Instead, use
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
agentinstead.
- This option does not exist. You need to pass an
cancelToken- This option does not exist, but will be implemented soon. For now, use
promise.cancel()orstream.destroy().
- This option does not exist, but will be implemented soon. For now, use
paramsSerializer- This option does not exist.
maxBodyLength- This option does not exist.
The response object is different as well:
response.data→response.bodyresponse.status→response.statusCoderesponse.statusText→response.statusMessageresponse.config→response.request.optionsresponse.request- Returns a Got stream.
The response.headers object remains the same.
Got offers hooks instead, which are more flexible.
Errors look the same, with the difference error.request returns a Got stream. Furthermore, Got provides more details to make debugging easier.
While Got doesn't support AbortController yet, you can use promise.cancel().
Convenience methods, such as axios.get(…) etc. remain the same: got.get(…). Instead of axios.create(…) use got.extend(…).
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.