@@ -46,6 +46,7 @@ yarn add superagent
46
46
``` js
47
47
const superagent = require (' superagent' );
48
48
49
+ // callback
49
50
superagent
50
51
.post (' /api/pet' )
51
52
.send ({ name: ' Manny' , species: ' cat' }) // sends a JSON post body
@@ -54,6 +55,19 @@ superagent
54
55
.end ((err , res ) => {
55
56
// Calling the end function will send the request
56
57
});
58
+
59
+ // promise with then/catch
60
+ superagent .post (' /api/pet' ).then (console .log ).catch (console .error );
61
+
62
+ // promise with async/await
63
+ (async () => {
64
+ try {
65
+ const res = await superagent .post (' /api/pet' );
66
+ console .log (res);
67
+ } catch (err) {
68
+ console .error (err);
69
+ }
70
+ })();
57
71
```
58
72
59
73
### Browser
@@ -69,6 +83,8 @@ Browser-ready versions of this module are available via [jsdelivr][], [unpkg][],
69
83
This is the solution for you if you're just using ` <script> ` tags everywhere!
70
84
71
85
``` html
86
+ <!-- https://github.com/Financial-Times/polyfill-service/issues/1944 -->
87
+ <script src =" https://polyfill.io/v3/polyfill.min.js?features=Array.from%2CPromise%2CSymbol%2CObject.setPrototypeOf" ></script >
72
88
<script src =" https://cdn.jsdelivr.net/npm/superagent" ></script >
73
89
<!-- if you wish to use unpkg.com instead: -->
74
90
<!-- <script src="https://unpkg.com/superagent"></script> -->
@@ -141,7 +157,14 @@ If you are using [browserify][], [webpack][], [rollup][], or another bundler, th
141
157
142
158
### Required Browser Features
143
159
144
- * IE9 requires a polyfill for ` window.FormData ` (we recommend [ formdata-polyfill] [ ] )
160
+ We recommend using < https://polyfill.io > (specifically with the bundle mentioned in [ VanillaJS] ( #vanillajs ) above):
161
+
162
+ ``` html
163
+ <script src =" https://polyfill.io/v3/polyfill.min.js?features=Array.from%2CPromise%2CSymbol%2CObject.setPrototypeOf" ></script >
164
+ ```
165
+
166
+ * IE 9-10 requires a polyfill for ` Promise ` , ` Array.from ` , ` Symbol ` , ` Object.getOwnPropertySymbols ` , and ` Object.setPrototypeOf `
167
+ * IE 9 requires a polyfill for ` window.FormData ` (we recommend [ formdata-polyfill] [ ] )
145
168
146
169
147
170
## Plugins
@@ -223,7 +246,7 @@ Our breaking changes are mostly in rarely used functionality and from stricter e
223
246
[ MIT] ( LICENSE ) © TJ Holowaychuk
224
247
225
248
226
- ##
249
+ ##
227
250
228
251
[ npm ] : https://www.npmjs.com/
229
252
0 commit comments