Re: [whatwg] Fetch: asFormData()

On Wed, Jun 25, 2014 at 4:51 PM, Jake Archibald <jaffathecake@gmail.com> wrote:
> On 25 June 2014 04:50, Anne van Kesteren <annevk@annevk.nl> wrote:
>> Do we want to keep that tradition and have both asFormData() and
>> asURLSearchParams() or should we embed some smarts in the asFormData()
>> algorithm? (FormData is basically a more general URLSearchParams as it
>> can handle Blob/File objects as well as strings.)
>
> A single asFormData() sounds useful and intuitive. Are you suggesting it'd
> always return a FormData object even if it was urlencoded? That sounds
> better than returning objects of different types.

Yes, however, that does mean asFormData() would inspect the MIME type
whereas other as*() methods do not. To be clear, the other suggestion
was not to vary the return type. Some options:

1) Have asFormData() check the MIME type for urlencoded. If it is
urlencoded, urlencoded-parse into FormData. Otherwise, formdata-parse
into FormData.

2) Have both asFormData() and asURLSearchParams(). The former
formdata-parse into FormData. The latter urlencoded-parse into
URLSearchParams.

1a) Like 1), but check MIME in the otherwise clause. Reject if neither
MIME type is there.

2a) Like 2), but check MIME. Reject if MIME type is incorrect.

3) Have 1/1a, but also asURLSearchParams() per 2/2a.

Feelings:

1) Simple, works. 2) Also simple, but harder for developers. 1a/2a
meh. 3) No need for asURLSearchParams if asFormData handles it
already.


-- 
http://annevankesteren.nl/

Received on Wednesday, 25 June 2014 15:00:13 UTC