Simple, typed wrapper of an Axios instance for Nextcloud https://npmjs.org/@nextcloud/axios
Перейти к файлу
dependabot[bot] c32117d479
chore(deps-dev): Bump happy-dom from 15.7.4 to 15.11.6
Bumps [happy-dom](https://github.com/capricorn86/happy-dom) from 15.7.4 to 15.11.6.
- [Release notes](https://github.com/capricorn86/happy-dom/releases)
- [Commits](https://github.com/capricorn86/happy-dom/compare/v15.7.4...v15.11.6)

---
updated-dependencies:
- dependency-name: happy-dom
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-16 02:34:51 +00:00
.github
LICENSES
lib style: separate license comment from code 2024-10-19 09:57:11 +02:00
test
.eslintrc.json
.gitignore
AUTHORS.md
CHANGELOG.md
LICENSE
README.md
REUSE.toml
package-lock.json chore(deps-dev): Bump happy-dom from 15.7.4 to 15.11.6 2024-11-16 02:34:51 +00:00
package.json chore(deps-dev): Bump happy-dom from 15.7.4 to 15.11.6 2024-11-16 02:34:51 +00:00
tsconfig.json
vite.config.ts
vitest.config.ts

README.md

@nextcloud/axios

REUSE status Build Status npm code coverage

Simple, typed wrapper of an Axios instance for Nextcloud that automatically sends authentication headers. Cancellation is supported as well.

Installation

npm install @nextcloud/axios --save
yarn add @nextcloud/axios

Usage

import axios from '@nextcloud/axios'

axios.get('nextcloud.com')

See https://github.com/axios/axios for details.

Defining baseURL

You are able to define baseURL to simplify the usage of axios across your app.

import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'

const baseURL = generateUrl('/apps/your_app_id/api')

axios.defaults.baseURL = baseURL

Retry handling

This package can optionally retry requests if they fail due to Nextcloud's maintenance mode. To activate this feature, pass retryIfMaintenanceMode: true into the request options. This mechanism will only catch relatively short server maintenance downtime in the range of seconds to a minute. Any longer downtime still has to be handled by the application, show feedback to the user, reload the page etc.

import axios from '@nextcloud/axios'

const pizzas = await axios.get('/apps/pizza/api/pizzas', {
    retryIfMaintenanceMode: true,
})
const myPizza = await axios.post('/apps/pizza/api/pizzas', { toppings: ['pineapple'] }, {
    retryIfMaintenanceMode: true,
})

Expired sessions handling

This package can optionally trigger a page reload whenever a request fails due to an expired user session. This interrupts application logic and should be the last resort. If possible, handle the expired session higher up in the application.

import axios from '@nextcloud/axios'

const response = await axios.get('/apps/foo/api/bar', {
    reloadExpiredSession: true,
})

References