0.1.34 • Published 4 months ago

cafetch v0.1.34

Weekly downloads
-
License
-
Repository
github
Last release
4 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.34

4 months ago

0.1.32

4 months ago

0.1.33

4 months ago

0.1.31

4 months ago

0.1.30

5 months ago

0.1.28

5 months ago

0.1.29

5 months ago

0.1.27

5 months ago

0.1.27-legacy

5 months ago

0.1.20

6 months ago

0.1.21

6 months ago

0.1.22

6 months ago

0.1.23

6 months ago

0.1.24

6 months ago

0.1.25

5 months ago

0.1.26

5 months ago

0.1.19

6 months ago

0.1.18

1 year ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.10

2 years ago

0.1.8

2 years ago

0.1.9

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.7

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago