0.1.40 • Published 7 months ago

cafetch v0.1.40

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago
import { registerEndpoint, request } from 'cafetch';


// register endpoint config
registerEndpoint({
  endpoint: 'endpoint1',
  fetchPolicy: 'cache-first',
  url: 'https://api.github.com/',
  method: 'GET',
  headers: { 'content-type': 'application/json' },
});
registerEndpoint([
  {
    endpoint: 'endpoint2',
    fetchPolicy: 'network-only',
    url: 'https://api.github.com/',
    method: 'POST',
    headers: { 'content-type': 'application/json' },
  }
]);

// request endpoint
request({ endpoint: 'endpoint1', url: 'https://api.github.com/' })
  .on('data', (response) => console.log(1, response))
  .on('error', (error) => console.log(1, error))
;
request({ endpoint: 'endpoint2', body: { id: '123' } })
  .on('data', (response) => console.log(2, response))
  .on('error', (error) => console.log(2, error))
;

// request with url
request('https://api.github.com/', { method: 'GET', fetchPolicy: 'cache-only' })
  .on('data', (response) => console.log(3, response))
  .on('error', (error) => console.log(3, error))
;
request('https://api.github.com/', {
  method: 'POST',
  body: { field: 'replace body' },
})
  .on('data', (response) => console.log(4, response))
  .on('error', (error) => console.log(4, error))
;

setTimeout(() => {
  // Get the results from the cache and send the request,
  // The above GET request will also receive a data event when the result is obtained
  request('https://api.github.com/', { fetchPolicy: 'cache-and-network' })
    .on('data', (response) => console.log(5, response))
    .on('error', (error) => console.log(5, error))
  ;
}, 1000);
0.1.40

7 months ago

0.2.1

7 months ago

0.1.39

7 months ago

0.1.38

10 months ago

0.1.36

11 months ago

0.1.37

11 months ago

0.1.35

1 year ago

0.1.34

1 year ago

0.1.32

1 year ago

0.1.33

1 year ago

0.1.31

2 years ago

0.1.30

2 years ago

0.1.28

2 years ago

0.1.29

2 years ago

0.1.27

2 years ago

0.1.27-legacy

2 years ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

2 years ago

0.1.25

2 years ago

0.1.26

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.7

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago