You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* In your HTML files : `<script src="your/path/to/jsonclient.js"></script>` (exposes the variable `$json`)
21
+
* In your HTML files : `<script src="your/path/to/dist/jsonclient.js"></script>` (exposes the variable `$json`)
22
22
23
23
24
24
@@ -62,7 +62,66 @@ $json.post :: (
62
62
63
63
64
64
65
-
If you have any doubts, you could refer to [Mozilla's guide on how to provide options to `fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Supplying_request_options) or ask for advices on my Discord server.
65
+
If you have any doubts, you could refer to [Mozilla's guide on how to provide options to `fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Supplying_request_options) or ask for advices on my [Discord server](https://discord.gg/JtWAjbw).
66
+
67
+
## Hooks and defaults
68
+
69
+
There are a few ways you can customize your JSON client (POST requests only) :
70
+
71
+
* Pass your custom settings as the third argument
72
+
* Change the default values
73
+
74
+
75
+
76
+
Default values are located in the object `$json.defaults` and are classified per HTTP methods (only those supported).
77
+
78
+
79
+
80
+
## Dependencies
81
+
82
+
There are only two dependencies :
83
+
84
+
*[fetchJSON](https://www.npmjs.com/package/fetch_json) : Used in developpement as the GET request provider (I'm the on that needs it)
85
+
* The Fetch API or `fetch` : As part of the Fetch API, `fetch` allows to emit HTTP requests. This library is heavily based around this function and therefore requires it, modern browsers implement it but there are also a lot of polyfills out there, here are two of them :
86
+
*[whatwg-fetch](https://www.npmjs.com/package/whatwg-fetch) : For old browsers
87
+
*[node-fetch](https://www.npmjs.com/package/node-fetch) : For Node-based environments
88
+
89
+
90
+
91
+
## Troubleshooting
92
+
93
+
If you don't find an answer to your problem, feel free to ask for help on my [Discord server](https://discord.gg/JtWAjbw).
94
+
95
+
96
+
97
+
**I can't use this library except by including it directly in the HTML**
98
+
99
+
> Until v1.1.0, there was an issue were the build process would simplify a conditional occuring in the UMD which would break the code for usage outside of the browser.
100
+
>
101
+
> This has been fixed in v1.1.0 by simply declaring the transpiled `build-babel/jsonclient.esm.js` file as the entry point of the application, thus making it available to use everywhere. As a sidenote, I'd like to point out that direct usage in the browser is done by including `dist/jsonclient.js` (which is not the entry point anymore).
102
+
>
103
+
>
104
+
>
105
+
> Make sure that the version of the library you have is at least 1.1.0 (check the `package.json` file), if not update it for the latest version.
106
+
>
107
+
> If you're still having this problem post v1.1.0, feel free to [open an issue on GitHub]("url here boi").
108
+
109
+
110
+
111
+
**I cannot find `$json.postOptions`, where are they ?**
112
+
113
+
> Since v1.1.0, `$json.postOptions` has been renamed `$json.postOptionsEnums` in order to avoid any kind of confusion.
114
+
115
+
116
+
117
+
**I am unable to get the requested data, there is an error in the console : `"Something went wrong during data inspection (data is not JSON or couldn't reach file)"`**
118
+
119
+
> This can mean two things (as said in the error message) :
120
+
>
121
+
> - The data is not **explicitely** marked as json (needs the`content-type` to be `application/json`, which is the standard way of identifying JSON)
122
+
> - The client was unable to reach the requested data (typo, wrong URL/URI, etc...)
0 commit comments