https://github.com/momsfriendlydevco/faxios
Tiny utility wrapper to add Axios functionality to Fetch
https://github.com/momsfriendlydevco/faxios
Last synced: over 1 year ago
JSON representation
Tiny utility wrapper to add Axios functionality to Fetch
- Host: GitHub
- URL: https://github.com/momsfriendlydevco/faxios
- Owner: MomsFriendlyDevCo
- Created: 2023-11-27T08:04:16.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-25T00:35:37.000Z (over 2 years ago)
- Last Synced: 2025-03-25T12:50:54.979Z (over 1 year ago)
- Language: JavaScript
- Size: 337 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
@MomsFriendlyDevCo/Faxios
=========================
Tiny utility wrapper to add Axios functionality to Fetch.
* **Automatic JSON decoding** - No more silly 'await request.json()` calls
* **Single object requests** - Throw around single AxiosRequest objects instead of the URL + config (except the URL query bits of course) stuff that Fetch insists you do
* **Less foot-guns** - URL query strings are automatically handled by the `params` options structure
* **Multipart data encoding** - Simply pass `{dataType: 'formData'}` to wrap all data inside `new FormData()` structures instead of standard JSON encoding
* **Simple default injection** - As with Axios, its simple to extend the `defaults` object to include common headers or data entities that should always be used
* **Error detection + warning (dev mode only)** - Faxios will yell at you nicely if you try to use a feature that you should probably use a full library for like parameter serialization, proxies or agent overrides
* **Intercept / tap into pre-fetch callbacks** - See the value of the final Fetch URL + FetchConfig while logging - see `onConfig()`
* **Fully compatible with Cloudflare workers** - ... and all its weird not-quite-JavaScript runtime API
```javascript
import faxios from '@momsfriendlydevco/faxios';
// Simple posting
let {data} = await faxios.post('https://somewebsite.com/api/something', {
foo: 1,
bar: 2,
baz: 3,
})
// Single object AxiosRequest parity
let {data} = await faxios({
method: 'PUT',
url: 'https://somewebsite.com/api/something',
auth: { // Handle Base64 basic auth natively
username: 'api',
password: 'mega-secure-api-token',
},
dataType: 'formData', // Encode data with `new FormData()` rather than `JSON.stringify()`
data: {
foo: 1,
bar: 2,
baz: 3,
},
})
```