Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
类 Axios 语法的原生 fetch API 请求封装库
Fetch based HTTP client with similar API to axios for browser and Node.js
fetch + axios = fexios (Just a joke)
fexios.post()
)index.umd.js 4.56 kB │ gzip: 2.01 kB │ map: 17.06 kB
包管理器/Using package manager
# Node Package Manager
npm install fexios
# Why not pnpm
pnpm add fexios
# Or yarn?
yarn add fexios
Then import the library and enjoy:
import fexios, { createFexios, Fexios } from 'fexios'
// Using directly
fexios.get('https://zh.moegirl.org.cn/api.php')
// With options
const fexios = createFexios(/* options */)
const fexios = new Fexios(/* options */)
const fexios = Fexios.create(/* options */)
在浏览器中直接使用/Use directly in the browser
import('https://unpkg.com/fexios?module').then(({ createFexios }) => {
const fexios = createFexios(/* options */)
})
<script src="https://unpkg.com/fexios"></script>
<script>
// Using directly
fexios.get('https://zh.moegirl.org.cn/api.php')
// With options
const { createFexios } = Fexios
const fexios = createFexios(/* options */)
</script>
You can find some sample code snippets here.
export type FexiosConfigs = {
baseURL: string
query: Record<string, string | number | boolean> | URLSearchParams
headers: Record<string, string> | Headers
credentials: 'omit' | 'same-origin' | 'include'
responseType: 'json' | 'blob' | 'text'
}
const DEFAULT_CONFIGS = {
baseURL: '',
credentials: 'same-origin',
headers: {
'content-type': 'application/json; charset=UTF-8',
},
query: {},
responseType: 'json',
}
fexios.request<T>(config): Promise<FexiosResponse<T>>
export interface FexiosRequestOptions {
baseURL?: string
method?: FexiosMethods
credentials?: 'omit' | 'same-origin' | 'include'
headers?: Record<string, string> | Headers
query?: Record<string, string | number | boolean> | URLSearchParams
body?: Record<string, any> | string | FormData | URLSearchParams
responseType?: 'json' | 'blob' | 'text'
}
Response
export type FexiosResponse<T = any> = {
rawRequest: Request
rawResponse: Response
ok: boolean
status: number
statusText: string
headers: Headers
isGood: boolean
data: T
}
And common request methods aliases:
export interface FexiosContext<T = any> extends FexiosRequestOptions {
url: string // may changes after beforeInit
rawRequest?: Request // provide in beforeRequest
rawResponse?: Response // provide in afterRequest
response?: FexiosResponse // provide in afterRequest
data?: T // provide in afterRequest
}
export type FexiosHook<C = unknown> = (context: C) => AwaitAble<C | false>
export type FexiosEvents = 'beforeInit' | 'beforeRequest' | 'afterResponse'
You can modify context in hooks' callback then return it as brand new context™.
Return false
to abort request immediately.
const fexios = new Fexios()
fexios.on('beforeRequest', async (ctx) => {
if (new URL(ctx.url).path === '/foo') {
return false
} else {
ctx.query.foo = 'bar'
}
return ctx
})
Oh, this is mimicked from axios. Just sweet sugar.
// They are same
fexios.on('beforeRequest', async (ctx) => {})
fexios.interceptors.request.use((ctx) => {})
// Bro, they are just same
fexios.on('afterResponse', async (ctx) => {})
fexios.interceptors.response.use((ctx) => {})
MIT License
Copyright (c) 2023 机智的小鱼君 (A.K.A. Dragon-Fish)
FAQs
Fetch based HTTP client with similar API to axios for browser and Node.js
The npm package fexios receives a total of 0 weekly downloads. As such, fexios popularity was classified as not popular.
We found that fexios demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.