apicase-adapter-fetch
Advanced tools
Comparing version 0.2.7 to 1.0.0
{ | ||
"name": "apicase-adapter-fetch", | ||
"version": "0.2.7", | ||
"description": "Fetch adapter for Apicase", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"repository": "https://github.com/apicase/adapter-fetch", | ||
"author": "Anton Kosykh", | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "eslint --fix index.js" | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^2.0.0", | ||
"path-to-regexp": "^2.1.0" | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/npm/deprecate-holder.git" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.11.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^5.2.1", | ||
"eslint-plugin-promise": "^3.6.0", | ||
"eslint-plugin-standard": "^3.0.1" | ||
} | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/npm/deprecate-holder/issues" | ||
}, | ||
"homepage": "https://github.com/npm/deprecate-holder#readme" | ||
} |
167
README.md
@@ -1,166 +0,5 @@ | ||
# apicase-adapter-fetch | ||
# Deprecated Package | ||
Fetch adapter for apicase-core | ||
This package is no longer supported and has been deprecated. To avoid malicious use, npm is hanging on to the package name. | ||
## Installation | ||
1. Install via NPM | ||
``` | ||
npm install apicase-adapter-fetch | ||
``` | ||
2. Import it | ||
```javascript | ||
import { apicase } from 'apicase-core' | ||
import fetch from 'apicase-adapter-fetch' | ||
const fetchAPI = apicase(fetch) | ||
``` | ||
3. If you use Node.js, use this instead of previous | ||
```javascript | ||
const apicase = require('apicase-core').default | ||
const fetch = require('apicase-adapter-fetch/node') | ||
const fetchAPI = apicase(fetch) | ||
``` | ||
We use [**node-fetch**](https://www.npmjs.com/package/node-fetch) as polyfill for Node.js | ||
## Basic usage | ||
```javascript | ||
fetchAPI({ | ||
url: '/api/posts', | ||
headers: { token: 'my_secret_token' }, | ||
query: { userId: 1 } | ||
}) | ||
.then(console.log) | ||
.catch(console.error) | ||
``` | ||
## Response format | ||
```javascript | ||
{ | ||
// true if everything is ok | ||
// false if got bad status or another errors happened | ||
"success": Boolean, | ||
// Response.body | ||
// null, if error | ||
"data": any, | ||
// Error | ||
// null, if no errors | ||
"error": any, | ||
// Response.status | ||
// null, if no-request error happened | ||
"status": Number|null, | ||
// Response.statusText | ||
// null, if no-request error happened | ||
"statustext": String|null | ||
} | ||
``` | ||
## Features | ||
### Url params | ||
Fetch adapter has [**path-to-regexp**](https://github.com/pillarjs/path-to-regexp) to pass urls params smarter. | ||
Params are stored in `params` property | ||
```javascript | ||
fetchAPI({ | ||
url: '/api/posts/:id', | ||
params: { id: 1 } | ||
}) | ||
// => GET /api/posts/1 | ||
``` | ||
### Query params | ||
You can define query params in `query` property | ||
```javascript | ||
fetchAPI({ | ||
url: '/api/posts', | ||
query: { userId: 1 } | ||
}) | ||
// => GET /api/posts?userId=1 | ||
``` | ||
### Status validation | ||
If you have some specific API, you can define custom status validation | ||
```javascript | ||
fetchAPI({ | ||
url: '/api/posts', | ||
validateStatus: status => status === 200 | ||
}) | ||
``` | ||
Default status validation behaviour is: | ||
```javascript | ||
function(status) { | ||
return status >= 200 && status < 300 | ||
} | ||
``` | ||
### Url concatenation in services | ||
Extended services will have concatenated URI, if the next part doesn't start with `/`: | ||
```javascript | ||
const service1 = new ApiService(fetch, { url: '/api' }) | ||
// { "url": "/api/posts" } | ||
const service2 = service1.extend({ url: 'posts' }) | ||
// { "url": "/posts" } | ||
const service3 = service1.extend({ url: '/posts' }) | ||
``` | ||
## Full payload params list | ||
```javascript | ||
{ | ||
// Request URL | ||
"url": String, | ||
// Response parser | ||
// default: 'json' | ||
"parser": String, | ||
// Request method | ||
// default: 'GET' | ||
"method": String, | ||
// Request headers | ||
// default: {} | ||
"headers": Object, | ||
// Request body | ||
// default: undefined | ||
"body": Object|FormData, | ||
// Credentials | ||
// default: 'omit' | ||
"credentials": String, | ||
// URL params | ||
// default: {} | ||
"params": Object, | ||
// Query params | ||
// default: {} | ||
"query": Object, | ||
// Status validation callback | ||
// default: status => status >= 200 && status < 300 | ||
"validateStatus": Function | ||
} | ||
``` | ||
## Author | ||
[Anton Kosykh](https://github.com/Kelin2025) | ||
## License | ||
MIT | ||
Please contact support@npmjs.com if you have questions about this 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
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
0
1
0
683
2
0
6
- Removednode-fetch@^2.0.0
- Removedpath-to-regexp@^2.1.0
- Removednode-fetch@2.7.0(transitive)
- Removedpath-to-regexp@2.4.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)