Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "fitch", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Test using fetch API", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -5,8 +5,86 @@ ![Fitch.js](https://github.com/raphaelpor/fitch.js/raw/master/assets/fitch-mini.png) | ||
## Run local | ||
## Get started | ||
### Install | ||
```sh | ||
git clone https://github.com/raphaelpor/fitch.js && cd fitch.js | ||
npm i | ||
npm i --save fitch | ||
``` | ||
## Use | ||
** With ES2015 or TypeScript:** | ||
```js | ||
import fitch from 'fitch' | ||
``` | ||
**CommonJS:** | ||
```js | ||
const fitch = require('fitch') | ||
``` | ||
**UMD:** | ||
```html | ||
<script src="node_modules/fitch/src/index.js"></script> | ||
``` | ||
### Make your first request: | ||
```js | ||
fitch.get(apiUrl) | ||
.then(data => console.log(data)) | ||
``` | ||
## Methods available: | ||
### get | ||
```js | ||
fitch.get(apiUrl) | ||
.then(data => console.log(data)) | ||
``` | ||
### post | ||
```js | ||
const req = {body: {name: 'Happy cat'}} | ||
fitch.get(apiUrl, req) | ||
.then(data => console.log(data)) | ||
``` | ||
### put | ||
```js | ||
const req = {body: {name: 'Happy cat'}} | ||
fitch.get(apiUrl, req) | ||
.then(data => console.log(data)) | ||
``` | ||
### patch | ||
```js | ||
const req = {body: {name: 'Happy cat'}} | ||
fitch.get(apiUrl, req) | ||
.then(data => console.log(data)) | ||
``` | ||
### delete | ||
```js | ||
fitch.get(apiUrl) | ||
.then(data => console.log(data)) | ||
``` | ||
## Use with custom configuration | ||
```js | ||
fitch.get(apiUrl, config) | ||
.then(data => console.log(data)) | ||
``` | ||
## Contributig | ||
First yout need to fork this repository. Then: | ||
```sh | ||
npm i # install local dependencies | ||
npm start # run local server | ||
npm run watch:test # watch files inside src/ and tests/ | ||
npm run examples # run examples | ||
``` | ||
It is important that the code can be tested and pass in linter check. | ||
You can verify your code with ESLint, using `npm run lint`. |
@@ -17,4 +17,4 @@ module.exports = { | ||
mode, | ||
} | ||
}; | ||
}, | ||
} | ||
}; |
// Verify if is running in browser | ||
const nodeFetch = require('node-fetch'); | ||
const f = typeof window === 'undefined' ? nodeFetch : fetch | ||
const f = typeof window === 'undefined' ? nodeFetch : fetch; | ||
@@ -10,24 +10,24 @@ const config = require('./config'); | ||
get(url, req) { | ||
return this.request('GET', url, req) | ||
return this.request('GET', url, req); | ||
}, | ||
post(url, req) { | ||
return this.request('POST', url, req) | ||
return this.request('POST', url, req); | ||
}, | ||
put(url, req) { | ||
return this.request('PUT', url, req) | ||
return this.request('PUT', url, req); | ||
}, | ||
patch(url, req) { | ||
return this.request('PATCH', url, req) | ||
return this.request('PATCH', url, req); | ||
}, | ||
delete(url, req) { | ||
return this.request('DELETE', url, req) | ||
return this.request('DELETE', url, req); | ||
}, | ||
request(method, url, req) { | ||
const params = config.create(method, req) | ||
return f(url, params).then(this.check) | ||
const params = config.create(method, req); | ||
return f(url, params).then(this.check); | ||
}, | ||
@@ -37,5 +37,5 @@ | ||
if (resp.ok) { | ||
return resp.json() | ||
return resp.json(); | ||
} | ||
throw new Error(`${resp.status} - ${resp.statusText}.`) | ||
throw new Error(`${resp.status} - ${resp.statusText}.`); | ||
}, | ||
@@ -46,2 +46,2 @@ | ||
}, | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90
3929
9
7