axlejs
v1.1.1
Published
Fetch, supercharged.
Downloads
7
Maintainers
Readme
AxleJS
Fetch, supercharged.
About
The Fetch Web API is great, but it could be better.
AxleJS supercharges fetch, with better error handling, easier to use options, can automatically follow redirects, an easier way to manage and view headers and search queries, custom response and request classes and methods, and a lot more.
Documentation
Features
- Functions for all HTTP Restful Methods.
- Use built-in middleware or make custom middleware.
- Very small, ~10KB Minified and ~17KB Unminified.
- Fast and easy to use.
- Documentation.
- Makes fetch easier to use.
- Better Error handling.
- Adds cancellation to fetch api.
- Custom and Extended Response and Request classes.
- Written in TypeScript.
- Built-in TypeDefs.
How to Download
GitHub
- Download the latest release from GitHub.
- Unzip and move contents into your project.
- Import AxleJS with the ES6 Import Syntax.
- Read the documentation.
NPM
- Run
npm i axlejs
. - Import AxleJS with the ES6 Import Syntax.
- Read the documentation.
CDN
- Import from https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js or for minified version https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js.
- Read the documentation.
Quick Start
In order to use AxleJS, you will need to download it first. Choose a way to download it.
After you have downloaded it import AxleJS into your project.
// NPM
import Axle from 'axlejs';
// GitHub
import Axle from 'pathToAxle/index.js';
// CDN
import Axle from 'cdnLinkHere';
// ------------
// For minified versions
// NPM
import Axle from 'axlejs/dist/index.min.js';
// GitHub
import Axle from 'pathToAxle/index.min.js';
// CDN
import Axle from 'minifiedCdnLinkHere';
To access AxleTypes for typescript, import like the following.
import Axle, { AxleTypes } from 'pathToAxle';
Making a request.
To make a request, you call Axle.<method>().
import Axle from 'pathToAxle';
// post
Axle.post('https://someApi.com/api/test',
// Data to post to server
{
someDataHere: 'AxleJS'
},
// AxleOptions which is fetch api options but extended and slightly modified (check docs), this is optional and the default value for Axle.post
{
mode: 'cors',
cache: 'default',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
}
);
// get
Axle.get('https://someApi.com/home',
// AxleOptions which is fetch api options but extended and slightly modified (check docs), this is optional and the default value for Axle.get
{
mode: 'cors',
cache: 'default',
}
)
// Any other http restful methods are available. Check https://www.restapitutorial.com/lessons/httpmethods.html for all HTTP Methods for Restful services
Cancelling a request is just as easy with AxleJS.
import Axle from 'pathToAxle';
const cancelMark = new Axle.cancelMark();
const cancelSignal = cancelMark.signal;
Axle.post('https://someApi.com/api/test',
// Data to post to server
{
someDataHere: 'AxleJS'
},
// AxleOptions which is fetch api options but extended and slightly modified (check docs), this is optional and the default value for Axle.post
{
mode: 'cors',
cache: 'default',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
// insert cancelSignal here
// this is native to the fetch api by using an AbortController and an AbortSignal
signal: cancelSignal
}
);
// Cancel request with an optional error message
cancelMark.cancel('Canceled AxleRequest.');
For more info, read the documentation.
Contributor's Guide
Requirements
- Must know TypeScript, Git, NPM, and how the Fetch API works and how to use it.
- Must read and agree to the Code of Conduct and Contributing Guidelines.
How to Contribute
- Fork the repository on GitHub.
- Create a new branch on GitHub named after what you are doing, such as a bugfix, feature, or patch. EX: patch-update-readme
- Clone your forked repository to your local machine.
- CD into your cloned repository and run
npm install
to install all the devDependencies. - Run
npm build
or press CTRL + SHIFT + B on vscode to compile, bundles, and minify the files. - Create a new local branch with the same name as your new remote branch.
- Make your changes.
- Build your changes with
npm build
or press CTRL + SHIFT + B on vscode. - Test your changes on codesandbox or any other platform.
- Stage, Commit, and Push your changes on your branch.
- Create a pull request to merge onto the staging branch.
- State all changes as a changelog in the pull request.
- Wait for your pull request to be reviewed and possibly merged.
- Thanks for contributing!
File Structure
- Src directory - All the source code is in here
- Lib directory - TypeScript files are compiled into JavaScript into here.
- Dist directory - The Bundled and Minified files are here as well as the TypeScript declaration files. This is the final build.
- Scripts directory - Shell scripts such as the build script which compiles, bundles, and minifies the files is located here.
Developer Scripts
npm run test
- Opens the test codesandbox in your default browser.npm run build
- Compiles, Bundles, and Minifies the file to create the final product in the dist directory.npm run bundle
- Bundles everything in the lib directory with webpack and outputs to dist.npm run format
- Uses prettier to format all files in the src directory.npm run format:watch
- Listens for changes on files and formats those files on change.npm run lint
- Uses eslint to lint all files in the src directory.npm run lint:watch
- Listens for changes on files and lints those files on change.npm run lint:fix
- Uses eslint to lint and fix all files in the src directory.npm run minify
- Uses uglifyjs to minify the bundled file in the dist directory and outputs in the dist directory.
License
Author
Bleart Emini - ksplatdev