Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: implement formData body support? #20

Open
guifromrio opened this issue Aug 11, 2016 · 5 comments
Open

Discussion: implement formData body support? #20

guifromrio opened this issue Aug 11, 2016 · 5 comments

Comments

@guifromrio
Copy link

We could implement support for multipart/form-data by being compatible with a form-data-like body. Something like checking for a getHeaders function?

@jonathanong
Copy link
Contributor

i personally hate multipart. is this for request or response body?

@haoxins
Copy link
Member

haoxins commented Aug 12, 2016

I dislike multipart too. But it's useful. 😢
(For me, I have to request some APIs by form-data)

BTW, https://github.com/visionmedia/superagent support multipart/form-data. 😄

@jonathanong
Copy link
Contributor

@firstdoit would you like to be a maintainer? this module does basically everything i need already, so i'm not really actively maintaining it

@guifromrio
Copy link
Author

@jonathanong that would be lovely. This module is generally very good, but lacks a couple of tiny features that would really make it shine in my opinion.
I started using it because of it's well-behaved size/amount of deps. Comparing this to request-promise:

npm i request request-promise
cloc node_modules/
    1723 text files.
    1659 unique files.
     290 files ignored.

https://github.com/AlDanial/cloc v 1.66  T=4.18 s (343.4 files/s, 30287.5 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JavaScript                    1267          13850          27276          65065
JSON                           130             38              0          17638
XML                              2            233             11           1948
YAML                            24             21             23            244
make                             7             27             28             64
Bourne Shell                     1              5              2             27
HTML                             2              2              0             27
C                                1              7              4             23
Lisp                             1              0              0              6
-------------------------------------------------------------------------------
SUM:                          1435          14183          27344          85042
———————————————————————————————————————
npm i requisition
cloc node_modules/
     196 text files.
     176 unique files.
      80 files ignored.

https://github.com/AlDanial/cloc v 1.66  T=0.53 s (217.2 files/s, 26757.2 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JSON                            28              0              0           9604
JavaScript                      81            693            836           3047
TypeScript                       4             13             37             44
YAML                             2              0              0             12
make                             1              1              0              3
-------------------------------------------------------------------------------
SUM:                           116            707            873          12710
———————————————————————————————————————

@guifromrio
Copy link
Author

As for form-data support, I believe we could do it without incurring in any extra deps: just document our support for form-data-like API. The idea would be for the user to create their own FormData object and pass it as body:

import FormData from 'form-data'
import request from 'requisition'
import {createReadStream} from 'fs'

const form = new FormData()
form.append('my_field', 'my value')
form.append('my_buffer', new Buffer(10))
form.append('my_file', createReadStream('/foo/bar.jpg'))

request.post('my/url/receiving/multipart').send(form)

Or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants