🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

fetch-with-json

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-with-json - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
+3
-2
package.json
{
"name": "fetch-with-json",
"description": "Some tweaks to the Fetch API to make it easier to communicate with the server using JSON.",
"version": "0.0.2",
"version": "0.0.3",
"main": "lib/index.js",

@@ -16,4 +16,5 @@ "types": "es/index.d.ts",

"build:lib": "tsc --outDir lib",
"dev": "tsc --outDir es --module esnext --watch --pretty false --preserveWatchOutput true",
"format": "prettier --write .",
"dev": "tsc --outDir es --module esnext --watch --pretty false --preserveWatchOutput true"
"release": "npm run build && npm publish --registry=https://registry.npmjs.org/"
},

@@ -20,0 +21,0 @@ "keywords": [

+5
-1

@@ -13,3 +13,3 @@ # Fetch with JSON

- Stringify the request data (the `json` field in the options) with `JSON.stringify` before sending it to the server as request body. [See the example here](#1-post-json-to-the-server).
- Stringify the request data (the `json` field in the options) with `JSON.stringify` before sending it to the server as request body. [See the example here](#1-posting-json-data).
- Set the request header `Content-Type` to `application/json` and `Accept` to `application/json, */*` if they are not set.

@@ -134,2 +134,6 @@ - Always try to parse response body as JSON no matter what the response header `Content-Type` is and assign the parsed result to `response.json`. If error has be thrown during parsing, `response.json` will be set to the text of the original response body, and the error will be assigned to `response.error`.

Please note that we are using the `body` field to upload the [FormData][form_data] instead of using the `json` field. The `body` field is declared in [the parameters of the Fetch API][fetch_params]. When `body` is set (not `null` or `undefined`), the `json` field will be ignored.
[form_data]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
### 5. Getting the original Response

@@ -136,0 +140,0 @@