1
1
# node-libcurl<!-- omit in toc -->
2
2
3
+ <p align =" center " >
3
4
<a href =" https://www.patreon.com/bePatron?u=19985213 " data-patreon-widget-type =" become-patron-button " >
4
- <
img src =
" https://c5.patreon.com/external/logo/[email protected] " width =
" 160 " >
5
+ <
img src =
" https://c5.patreon.com/external/logo/[email protected] " width =
" 190 " >
5
6
</a >
6
- <br >
7
+ </ p >
7
8
8
9
[ ![ NPM version] [ npm-image ]] [ npm-url ]
9
10
[ ![ node] [ node-image ]] [ node-url ]
36
37
37
38
- [ Quick Start] ( #quick-start )
38
39
- [ Install] ( #install )
39
- - [ Simple Request - Async / Await] ( #simple-request---async--await )
40
- - [ Simple Request] ( #simple-request )
41
- - [ Setting HTTP headers] ( #setting-http-headers )
40
+ - [ Simple Request - Async / Await using curly ] ( #simple-request---async--await-using-curly )
41
+ - [ Simple Request - Using Curl class ] ( #simple-request---using-curl-class )
42
+ - [ Setting HTTP headers] ( #setting-http-headers )
42
43
- [ Form Submission (Content-Type: application/x-www-form-urlencoded)] ( #form-submission-content-type-applicationx-www-form-urlencoded )
43
44
- [ MultiPart Upload / HttpPost libcurl Option (Content-Type: multipart/form-data)] ( #multipart-upload--httppost-libcurl-option-content-type-multipartform-data )
44
45
- [ API] ( #api )
70
71
``` shell
71
72
yarn add node-libcurl
72
73
```
73
- ### Simple Request - Async / Await
74
+ ### Simple Request - Async / Await using curly
74
75
> this API is experimental and is subject to changes without a major version bump
75
76
76
77
``` javascript
@@ -92,7 +93,21 @@ const { statusCode, data, headers } = await curly.post('http://httpbin.com/post'
92
93
})
93
94
```
94
95
95
- ### Simple Request
96
+ JSON POST example:
97
+ ``` javascript
98
+ const { curly } = require (' node-libcurl' )
99
+ const { data } = await curly .post (' http://httpbin.com/post' , {
100
+ postFields: JSON .stringify ({ field: ' value' }),
101
+ httpHeader: [
102
+ ' Content-Type: application/json' ,
103
+ ' Accept: application/json'
104
+ ],
105
+ })
106
+
107
+ console .log (JSON .parse (data))
108
+ ```
109
+
110
+ ### Simple Request - Using Curl class
96
111
``` javascript
97
112
const { Curl } = require (' node-libcurl' );
98
113
@@ -115,7 +130,7 @@ curl.on('error', curl.close.bind(curl));
115
130
curl .perform ();
116
131
```
117
132
118
- #### Setting HTTP headers
133
+ ### Setting HTTP headers
119
134
120
135
Pass an array of strings specifying headers
121
136
``` javascript
0 commit comments