# rkst

> a http lib with typescript

Latest version **1.0.6** (published 2021-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install rkst
pnpm add rkst
yarn add rkst
bun add rkst
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-04-29 |
| First published | 2021-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Asarua |
| Maintainers | asarua |
| Keywords | xhr, http, ajax, promise |

## Links

- npm: https://www.npmjs.com/package/rkst
- Repository: https://github.com/Asarua/rkst
- Homepage: https://github.com/Asarua/rkst#readme
- Issues: https://github.com/Asarua/rkst/issues
- npm.io page: https://npm.io/package/rkst

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2021-04-29
- 1.0.5 — 2021-04-29
- 1.0.4 — 2021-04-28
- 1.0.3 — 2021-04-28
- 1.0.2 — 2021-04-28
- 1.0.1 — 2021-04-28
- 1.0.0 — 2021-04-27

## README

# rkst

一个基于ts的http请求库

## 功能

- 提供了完善的ts类型支持，支持传入返回类型
- 使用Promise
- 支持两种自定义`before`、`after`拦截
- 支持预配置的高级模式
- 支持开箱即用的简单模式

## 下载

使用npm

```bash
npm install rkst
```

使用yarn

```bash
yarn add rkst
```

## 例子

> 使用`configureRkst`配置拦截器

```typescript
import { configureRkst, ConfigureRkst } from 'rkst'

const before: ConfigureRkst['before'] = options => {
  console.log(options, 'before')
  return options
}

const after: ConfigureRkst['after'] = options => {
  console.log(options, 'after')
  return options
}

const rkst = configureRkst({
  before,
  after
})

export default {
  get(url) {
    return rkst({
      url,
      methods: 'get'
    })
  }
}
```

> 使用`rkst`直接请求

```typescript
import rkst from 'rkst'

export default {
  get(url) {
    return rkst({
      url,
      methods: 'get'
    }, before, after)
  }
}
```

> 使用`rkst.get`、`rkst.post`、`rkst.put`、`rkst.delete`直接请求

```typescript
import rkst from 'rkst'

rkst.get<{ a: 1 }>('baidu.com')
  .then(data => {
    // data的type === { a: 1 }
  })
```

> 通过泛型传递返回参数

```typescript
rkst<{ a: 1 }>({
  url,
  methods: 'get'
})
  .then(data => {
    // data的type === { a: 1 }
  })
```

> 通过封装泛型统一处理类型（rkst的返回类型会自动匹配get的返回类型，因此不用传参也可以完美的类型推倒）

```typescript
interface API {
  get: {
    'https://api.apiopen.top/searchAuthors?name=李白': {
      name: 123
    }
  }
}

export const get = <URL extends keyof API['get']>(url: URL): Promise<API['get'][URL]> => {
  return rkst({
    url,
    methods: 'get'
  })
}

```

## License

[`MIT`](https://github.com/Asarua/rkst/LICENSE)

---
_Source: https://npm.io/package/rkst · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
