0.3.0 • Published 2 years ago

knict-fetch v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

knict-fetch

基于axios, 尝试让fetch 更清晰

How to use

0. create you node project

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

1. add to your project

npm install knict-fetch 

# or yarn add knict-fetch

2. set up typescrit

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

# generate a tsconfig.json 
tsc --init

3. edit tsconfig.json

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

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

4. create files with content

4.1 GithubService.ts

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

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

tsc && node index.js
0.3.0

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.2.0

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.2

3 years ago