Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maximilianmairinger/ajaon
Asynchron js and json. A tiny, fetch based http client for the web.
https://github.com/maximilianmairinger/ajaon
async client fetch http json tiny web
Last synced: about 2 months ago
JSON representation
Asynchron js and json. A tiny, fetch based http client for the web.
- Host: GitHub
- URL: https://github.com/maximilianmairinger/ajaon
- Owner: maximilianMairinger
- Created: 2020-02-04T15:58:26.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-15T12:49:19.000Z (over 4 years ago)
- Last Synced: 2024-08-09T05:14:42.496Z (5 months ago)
- Topics: async, client, fetch, http, json, tiny, web
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/ajaon
- Size: 57.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ajaon
Asynchron js and json (ajaon). A tiny, fetch based http client for the web.
## Example
### Quick start
```js
import ajaon from "ajaon"// initialisation
let ajax = ajaon();let req = ajax.post("apiCall", {ok: "ok"})
let getReq = ajax.get("resource")req.then(console.log)
```### Abort Network Requests
```js
setTimeout(() => {
req.abort("Message")
}, 500)req.fail(console.error) // Abort: Message
```Abort, or a for any other reason failed network request, does not throw an `Error`, rather it calls all explicitly attached fail callbacks.
In this case, the `req` Promise would never be resolved.
### Initialisation options
The quick start example used no explicit initialisation options, however there are a couple of helpful customisations to be considered.
```ts
let apiUrl: string = "backend.myUrl.com" // Default: the baseUrl the website is renderd on
type SessKeyKey = {sessKeyKeyForStorage: string, sessKeyKeyForApi: string}
let sessKeyKey: string | SessKeyKey = "sess_key" // Default: "sessKey"
let storage: object = {} // Default: localStorage
let verbose: boolean = false // Default: truelet ajax = ajaon(apiUrl, sessKeyKey, storage, verbose)
```* **`apiUrl`**: Your backend might be located on a different [`baseUrl`]("https://www.npmjs.com/package/get-base-url") than your frontend. This could be injected in your build script for different environments (dev, uat, prod). Please note that when no protocol (`http` / `https`) is given, ajaon will try `https` on your *first* call; though if it fails ajaon will try `http` next (without closing the outwards facing `Promise`). The working protocol will be stored.
* **`sessKeyKey`**: TODO## Contribute
All feedback is appreciated. Create a pull request or write an issue.