# knict-fetch

> 基于axios， 尝试让fetch 更清晰

Latest version **0.3.0** (published 2022-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install knict-fetch
pnpm add knict-fetch
yarn add knict-fetch
bun add knict-fetch
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2022-09-16 |
| First published | 2021-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 21.5 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | kfdykme |

## Links

- npm: https://www.npmjs.com/package/knict-fetch
- npm.io page: https://npm.io/package/knict-fetch

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.21.4
- [knict](https://npm.io/package/knict.md) ^0.3.0
- [form-data](https://npm.io/package/form-data.md) ^4.0.0

## Recent versions

- 0.3.0 (latest) — 2022-09-16
- 0.2.0 — 2022-02-09
- 0.1.19 — 2022-02-09
- 0.1.18 — 2022-02-09
- 0.1.17 — 2022-02-09
- 0.1.16 — 2022-02-09
- 0.1.15 — 2022-02-09
- 0.1.14 — 2022-02-09
- 0.1.13 — 2022-02-09
- 0.1.12 — 2021-10-15
- 0.1.11 — 2021-10-15
- 0.1.10 — 2021-10-15
- 0.1.9 — 2021-10-15
- 0.1.8 — 2021-10-09
- 0.1.7 — 2021-10-02
- … 4 more at https://npm.io/package/knict-fetch/versions

## README

# knict-fetch

基于axios， 尝试让fetch 更清晰

# How to use

## 0. create you node project 

``` bash
mkdir my-fetch-project
cd my-fetch-project
npm init 
```

## 1. add to your project

``` bash

npm install knict-fetch 

# or yarn add knict-fetch
```

## 2. set up typescrit

``` bash
# make sure you can use tsc  
npm install -g tsc 

# generate a tsconfig.json 
tsc --init
```

## 3. edit tsconfig.json

修改tsconfig.json的以下字段， 其余保持不变

``` json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6", 
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
  }
}
```

## 4. create files with content

### 4.1 GithubService.ts

``` typescript 
import { HttpMethod } from 'knict-fetch'

const { GET, Path } = HttpMethod

const UnSupportPromise = () => {
    return Promise.resolve("Not Support")
}
export class GitHubService {

    @GET("/users/{user}/repos")
    repos(@Path('user') user: string): Promise<any> {
        return UnSupportPromise()
    }
}
```

### 4.2 index.ts
``` typescript
import { Knict, FetchClientBuilder } from 'knict-fetch'

import { GitHubService } from './GitHubService'


(async () => {

    const demo = Knict.builder(new FetchClientBuilder()
        .baseUrl('https://api.github.com')
    ).create(new GitHubService())

    let res:any = await demo.repos("yourusername").catch(console.error);
    console.info('repos result res', res)
    
})()
```

### 5 test knict-fetch

``` bash
tsc && node index.js
```

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