0.1.1 • Published 11 months ago

@kiritaniayaka/fetcha v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

fetcha

NPM Version npm downloads JSR JSR Score bundle JSDocs License

A minimal fetch client wrapper with interceptor.

Examples

const baseUrl = 'http://localhost:8000'

const fetcha = new FetchaBuilder()
	.useRequestInterceptor((info, init) => { // base url example
		return [`${baseUrl}${info}`, init]
	})
	.useResponseInterceptor(async (response) => { // interceptor could be async
		if (!response.ok())
			return toast('Some thing went wrong')
		return await response.json()
	})
	.build() // build a fetcha client

fetcha('/api/hello') // use it like fetch

License

MIT License © 2024 Kiritani Ayaka