Skip to content

Commit 703c951

Browse files
committed
docs: add COMMON_ISSUES and more examples to the README.md
1 parent 050a3fc commit 703c951

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

COMMON_ISSUES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Error: SSL peer certificate or SSH remote key was not Ok
2+
3+
You need to set either [`CAINFO`](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO.html) or [`CAPATH`](https://curl.haxx.se/libcurl/c/CURLOPT_CAPATH.html) options, or disable SSL verification with [`SSL_VERIFYPEER`](https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html) which is not recommended.
4+
5+
The certificate file can be obtained in multiple ways:
6+
1. Downloaded from https://curl.haxx.se/docs/caextract.html
7+
2. Creating a file with the contents of `tls.rootCertificates`, which was added with Node.js `v12.3.0`

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
- [Simple Request - Async / Await](#simple-request---async--await)
4040
- [Simple Request](#simple-request)
4141
- [Setting HTTP headers](#setting-http-headers)
42-
- [MultiPart Upload / HttpPost libcurl Option](#multipart-upload--httppost-libcurl-option)
42+
- [Form Submission (Content-Type: application/x-www-form-urlencoded)](#form-submission-content-type-applicationx-www-form-urlencoded)
43+
- [MultiPart Upload / HttpPost libcurl Option (Content-Type: multipart/form-data)](#multipart-upload--httppost-libcurl-option-content-type-multipartform-data)
4344
- [Benchmarks](#benchmarks)
4445
- [API](#api)
46+
- [Common Issues](#common-issues)
4547
- [Supported Libcurl Versions](#supported-libcurl-versions)
4648
- [For Enterprise](#for-enterprise)
4749
- [Detailed Installation](#detailed-installation)
@@ -77,6 +79,19 @@ const { curly } = require('node-libcurl');
7779
const { statusCode, data, headers } = await curly.get('http://www.google.com')
7880
```
7981

82+
Any option can be passed using their `FULLNAME` or a `lowerPascalCase` format:
83+
```javascript
84+
const querystring = require('querystring');
85+
const { curly } = require('node-libcurl');
86+
87+
const { statusCode, data, headers } = await curly.post('http://httpbin.com/post', {
88+
postFields: querystring.stringify({
89+
field: 'value',
90+
}),
91+
// can use `postFields` or `POSTFIELDS`
92+
})
93+
```
94+
8095
### Simple Request
8196
```javascript
8297
const { Curl } = require('node-libcurl');
@@ -108,7 +123,25 @@ curl.setOpt(Curl.option.HTTPHEADER,
108123
['Content-Type: application/x-amz-json-1.1'])
109124
```
110125

111-
### MultiPart Upload / HttpPost libcurl Option
126+
### Form Submission (Content-Type: application/x-www-form-urlencoded)
127+
```javascript
128+
const querystring = require('querystring');
129+
const { Curl } = require('node-libcurl');
130+
131+
const curl = new Curl();
132+
const close = curl.close.bind(curl);
133+
134+
curl.setOpt(Curl.option.URL, '127.0.0.1/upload');
135+
curl.setOpt(Curl.option.POST, true)
136+
curl.setOpt(Curl.option.POSTFIELDS, querystring.stringify({
137+
field: 'value',
138+
}));
139+
140+
curl.on('end', close);
141+
curl.on('error', close);
142+
```
143+
144+
### MultiPart Upload / HttpPost libcurl Option (Content-Type: multipart/form-data)
112145

113146
```javascript
114147
const { Curl } = require('node-libcurl');
@@ -139,6 +172,10 @@ Almost all [CURL options](https://curl.haxx.se/libcurl/c/curl_easy_setopt.html)
139172

140173
For more usage examples check the [examples folder](./examples).
141174

175+
## Common Issues
176+
177+
See [COMMON_ISSUES.md](./COMMON_ISSUES.md)
178+
142179
## Supported Libcurl Versions
143180

144181
The addon is only tested against libcurl version `7.50.0` and the latest one available.

0 commit comments

Comments
 (0)