Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xior

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xior - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

4

lib/interceptors.d.ts

@@ -1,2 +0,2 @@

import { XiorRequestConfig } from './types';
export declare function defaultRequestInterceptor(req: XiorRequestConfig): Promise<XiorRequestConfig>;
import { XiorInterceptorRequestConfig } from './types';
export declare function defaultRequestInterceptor(req: XiorInterceptorRequestConfig): Promise<XiorInterceptorRequestConfig>;

@@ -1,2 +0,2 @@

export interface XiorRequestConfig extends Omit<RequestInit, 'body'> {
export interface XiorRequestConfig<T = any> extends Omit<RequestInit, 'body'> {
url?: string;

@@ -19,2 +19,6 @@ headers?: Record<string, any>;

}
export type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & {
headers: Record<string, any>;
params: Record<string, any>;
};
export interface XiorResponse<T = any> {

@@ -26,4 +30,4 @@ data: T;

response: Response;
config: XiorRequestConfig;
config: XiorInterceptorRequestConfig;
request?: any;
}

@@ -1,2 +0,2 @@

import { XiorRequestConfig } from './types';
import { XiorInterceptorRequestConfig, XiorRequestConfig } from './types';
export declare class xior {

@@ -10,3 +10,3 @@ static create(options?: XiorRequestConfig): xior;

request: {
use: (fn: (config: XiorRequestConfig) => Promise<XiorRequestConfig> | XiorRequestConfig, onRejected?: ((error: any) => any) | undefined) => void;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => void;
};

@@ -16,11 +16,11 @@ response: {

data: any;
request: XiorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
request: XiorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
request: XiorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;

@@ -30,8 +30,6 @@ }, onRejected?: ((error: any) => any) | undefined) => void;

};
request<T>(options?: XiorRequestConfig & {
url: string;
}): Promise<{
request<T>(options?: XiorRequestConfig | string): Promise<{
data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -46,4 +44,4 @@ headers: Headers;

data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -56,4 +54,4 @@ headers: Headers;

data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -66,4 +64,4 @@ headers: Headers;

data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -76,4 +74,4 @@ headers: Headers;

data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -86,4 +84,4 @@ headers: Headers;

data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -96,4 +94,4 @@ headers: Headers;

data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -106,4 +104,4 @@ headers: Headers;

data: T;
request: XiorRequestConfig;
config: XiorRequestConfig;
request: XiorRequestConfig<any>;
config: XiorRequestConfig<any>;
response: Response;

@@ -110,0 +108,0 @@ headers: Headers;

@@ -31,3 +31,5 @@ "use strict";

constructor(options) {
this.requestInterceptors = [interceptors_1.defaultRequestInterceptor];
this.requestInterceptors = [
interceptors_1.defaultRequestInterceptor,
];
this.responseInterceptors = [];

@@ -55,3 +57,3 @@ this.config = options;

return __awaiter(this, void 0, void 0, function* () {
let requestObj = (0, utils_1.merge)(this.config || {}, options || {});
let requestObj = (0, utils_1.merge)(this.config || {}, typeof options === 'string' ? { url: options } : options || {}, { headers: {}, params: {} });
for (const item of this.requestInterceptors) {

@@ -58,0 +60,0 @@ requestObj = yield item(requestObj);

{
"name": "xior",
"version": "0.0.3",
"version": "0.0.4",
"description": "Axios similiar API request library but based on fetch",

@@ -21,4 +21,6 @@ "repository": "suhaotian/xior",

"test": "pnpm build:lib && node --test",
"prepare": "is-ci || pnpm build && husky",
"start-publish": "pnpm test && npm publish --registry=https://registry.npmjs.org"
"checktype": "tsc --noEmit",
"start-publish": "pnpm test && npm publish --registry=https://registry.npmjs.org",
"push": "git push && git lfs push --all origin",
"prepare": "is-ci || pnpm build && husky"
},

@@ -91,3 +93,3 @@ "dependencies": {

"request cache",
"repeat requests avoid"
"repeat requests filter"
],

@@ -94,0 +96,0 @@ "author": "suhaotian",

@@ -0,1 +1,9 @@

[![Build](https://github.com/suhaotian/xior/actions/workflows/check.yml/badge.svg)](https://github.com/suhaotian/xior/actions/workflows/check.yml)
[![npm version](https://badgen.net/npm/v/xior?color=green)](https://www.npmjs.com/package/xior)
[![minzipped size](https://badgen.net/badge/gzip/2.6kb/green)](https://bundlephobia.com/package/xior)
[![tree shaking](https://badgen.net/bundlephobia/tree-shaking/xior)](https://bundlephobia.com/package/xior)
![typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label&color=blue)
[![dependency](https://badgen.net/bundlephobia/dependency-count/xior)](https://bundlephobia.com/package/xior)
![license](https://badgen.net/npm/license/xior?color=blue)
# Xior

@@ -9,3 +17,3 @@

- 🔥 Use fetch
- 🚀 Lightweight ~5KB, Gzip ~2.0KB
- 🚀 Lightweight ~6KB, Gzip ~2.6KB
- 🤙 Support timeout and cancel request

@@ -16,2 +24,8 @@ - 👊 Unit tests

## Install
```bash
npm i xior
```
## Getting Started

@@ -35,2 +49,3 @@

// GET
async function getList() {

@@ -41,2 +56,3 @@ const { data } = await http.get('/list', { params: { page: 1, perPage: 20 } });

// POST
async function create() {

@@ -92,3 +108,3 @@ const { data } = await http.post(

The url will be like: `http://httpbin.org?a=1&b=[object object]`, to support nested objects in url encoded strings, use custom encode function `qs`'s `stringify` module:
The url will be like: `http://httpbin.org?a=1&b=[object object]`, to support nested objects url encoded, use `qs`'s `stringify` module:

@@ -117,3 +133,3 @@ ```ts

> Not like axios, xior don't support upload progess or download progress.
> Not like axios, xior doesn't support upload progess or download progress.

@@ -175,3 +191,3 @@ Use FormData to upload files.

### instance.interceptors.request.use
### xior.interceptors.request.use

@@ -191,3 +207,3 @@ ```ts

### instance.interceptors.response.use
### xior.interceptors.response.use

@@ -210,2 +226,17 @@ ```ts

### stream
> if the options `responseType` is `responseType: 'stream' | 'document' | 'arraybuffer' | 'blob'`, then xior will just return the original response: `{ response }`, you can do anthing with response you like:
```ts
import xior, { merge as deepMerge } from 'xior';
const instance = xior.create({
baseURL: 'http://httpbin.org',
});
instance.get('/stream', { responseType: 'stream' }).then(({ response }) => {
// `response` is the original response, like fetch('/stream').then(response => { console.log(response)})
});
```
## Use plugins

@@ -255,5 +286,5 @@

- Is `xior` 100% compatiable with `axios`? No
- How to upload files? Use
- How to show upload progress like axios? Not support.
- How to upload files? Use `FormData`
- How to show upload progress like axios? Doesn't support.
- What about response of `'stream' | 'document' | 'arraybuffer' | 'blob'` ? Use `responseType: 'stream' | 'document' | 'arraybuffer' | 'blob'`, will return original `{ response }`
- More: Anything else? create new issues let me know!
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc