From 88c9f6b8b05eda50c37dcfc5dcfeb1947059d026 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Thu, 14 Jan 2016 14:24:10 +0500 Subject: [PATCH] :memo: add example of Form Data usage --- readme.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/readme.md b/readme.md index 9affb8b..4c03fa2 100644 --- a/readme.md +++ b/readme.md @@ -221,6 +221,25 @@ got('google.com', { ``` +## Form data + +You can use the [`form-data`](https://www.npmjs.com/package/form-data) module to create POST request with form data: + +```js +const fs = require('fs'); +const got = require('got'); +const FormData = require('form-data'); +const form = new FormData(); + +form.append('my_file', fs.createReadStream('/foo/bar.jpg')); + +got.post('google.com', { + headers: form.getHeaders(), + body: form +}); +``` + + ## Unix Domain Sockets Requests can also be sent via [unix domain sockets](http://serverfault.com/questions/124517/whats-the-difference-between-unix-socket-and-tcp-ip-socket). Use the following URL scheme: `PROTOCOL://unix:SOCKET:PATH`.