aurelia / aurelia/http-client

Feature Request: .withForm() and .withFormData()

Open
#165 2 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
JavaScript
Stars
60
Forks
57
PR merge metrics
No merged PRs in 30d

Description

**I'm submitting a feature request**

* **Library Version:**
aurelia-http-client 1.0.4

**Please tell us about your environment:**
* **Operating System:**
macOS Sierra 10.12.3

* **Node Version:**
7.3.0

* **NPM Version:**
3.10.10

* **JSPM OR Webpack AND Version**
JSPM 0.16.52

* **Browser:**
all (browser-agnostic)

* **Language:**
ESNext

* **What is the motivation / use case for changing the behavior?**
The fluent API for building HTTP requests is fantastic, but I would like to suggest an enhancement: `.withForm()` and `.withFormData()`.

I realize that we can simply create a `FormData` object, according to the xhr2 spec, and then submit that using `HttpClient::post()`. But it would be both convenient and semantic to do this:

`
.withForm(formElement, formDataObject?)
`

or

`
.withFormData(formDataObject)
`

and then have that translated by `http-client` into a `FormData` instance behind the scenes. The former addresses those instances where the form data is built up from a an HTML form (with the optional ability to append additional data, according to the spec); and the latter addresses those instances where no HTML form is involved at all.

As it stands now, from looking at `http-client`, there's nothing connecting the `application/x-www-form-urlencoded` content type to the API semantically. One might wrestle for quite a while, as I did, with `.withParams()` and `.withContent()` to try to effect such a request, but with no success.

Just a suggestion...

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing HttpClient::post() flow and the .withParams() and .withContent() methods in http-client, then review how FormData is handled by XMLHttpRequest. Done means the proposed .withForm(formElement, formDataObject?) and .withFormData(formDataObject) APIs produce the intended form submissions for both HTML forms and standalone data.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.