Comparing version 1.0.0 to 1.0.1
@@ -780,3 +780,3 @@ /** | ||
* @param {Object} options optional options, sepcific for this single request | ||
* @return {Object} res camelCased response | ||
* @return {Object} res camelCased response | ||
*/ | ||
@@ -803,7 +803,13 @@ | ||
if (requestOptions.body) { | ||
requestOptions.body = changeCaseObject_1.snakeCase(requestOptions.body); | ||
var snakeCasedBody = changeCaseObject_1.snakeCase(requestOptions.body); | ||
requestOptions.body = JSON.stringify(snakeCasedBody); | ||
} | ||
return fetch('' + url + queryString$$1, _extends({}, requestOptions)).then(function (res) { | ||
if (!res.ok) throw new Error('API Response was not ok', res); | ||
if (!res.ok) { | ||
var error = new Error('API response was not ok.'); | ||
error.response = res; | ||
throw error; | ||
} | ||
return res; | ||
@@ -810,0 +816,0 @@ }).then(function (res) { |
@@ -782,3 +782,3 @@ 'use strict'; | ||
* @param {Object} options optional options, sepcific for this single request | ||
* @return {Object} res camelCased response | ||
* @return {Object} res camelCased response | ||
*/ | ||
@@ -805,7 +805,13 @@ | ||
if (requestOptions.body) { | ||
requestOptions.body = changeCaseObject_1.snakeCase(requestOptions.body); | ||
var snakeCasedBody = changeCaseObject_1.snakeCase(requestOptions.body); | ||
requestOptions.body = JSON.stringify(snakeCasedBody); | ||
} | ||
return fetch('' + url + queryString$$1, _extends({}, requestOptions)).then(function (res) { | ||
if (!res.ok) throw new Error('API Response was not ok', res); | ||
if (!res.ok) { | ||
var error = new Error('API response was not ok.'); | ||
error.response = res; | ||
throw error; | ||
} | ||
return res; | ||
@@ -812,0 +818,0 @@ }).then(function (res) { |
{ | ||
"name": "snuffles", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A wrapper around the native fetch function, returning the response body as a camelCased object", | ||
@@ -5,0 +5,0 @@ "author": "railslove", |
@@ -5,8 +5,8 @@ <p align="center"> | ||
> A wrapper around the native fetch function, providing a more convenient way to use it | ||
> A wrapper around the native fetch function, providing a more convenient way to use it for JSON requests | ||
![](https://travis-ci.org/railslove/snuffles.svg?branch=master) | ||
![](https://img.shields.io/github/license/railslove/snuffles.svg) | ||
![](https://img.shields.io/github/release/railslove/snuffles.svg) | ||
![](https://img.shields.io/npm/v/snuffels.svg) | ||
![](https://img.shields.io/github/tag/railslove/snuffles.svg) | ||
![](https://img.shields.io/npm/v/snuffles.svg) | ||
@@ -28,3 +28,3 @@ At its core, Snuffles is just a very slim wrapper around the [native `fetch` function](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch). It allows for setting a base url and default options for your request, provides some wrappers around some of the more frequently used HTTP methods and takes care of all casing. You send camelCased objects in, you get camelCased objects out. | ||
export default function myApiWrapper() { | ||
cosnt defaultOptions = { | ||
const defaultOptions = { | ||
headers: { | ||
@@ -76,3 +76,3 @@ 'X-AUTH-TOKEN': 'my-secret-token' | ||
const user = api.get('/user') | ||
const user = api.get('/user', options) | ||
@@ -88,2 +88,47 @@ // => fetch('http://base-url.tld/user?name=sirius&animal=dog') | ||
#### Response bodies | ||
Assuming `GET https://your-api/users/1` would return a response with a body of | ||
```json | ||
{ | ||
"user_name": "John Doe", | ||
"paid_user": false | ||
} | ||
``` | ||
If you make this request with snuffles, it would look like | ||
```js | ||
const api = new Snuffles('https://your-api') | ||
const res = api.get('/users/1') | ||
// res => | ||
// { | ||
// userName: "John Doe", | ||
// paidUser: false | ||
// } | ||
// | ||
``` | ||
#### Request bodies: | ||
```js | ||
const api = new Snuffles('http://base-url.tld') | ||
const options = { | ||
body: { | ||
'userName': 'sirius', | ||
'paidUser': true | ||
} | ||
} | ||
api.post('/users', options) | ||
// sends a request to 'http://base-url.tld/users', with the body | ||
// { | ||
// user_name: 'sirius', | ||
// paid_user: true | ||
// } | ||
``` | ||
## License | ||
@@ -90,0 +135,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
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
186583
1467
142
3