I’m trying to use a web API that was designed to work with HTTP POST requests from the form below. I want to post to it as in the examples at https://beta.observablehq.com/@chrisprice/rest-websockets and https://beta.observablehq.com/@mbostock/posting-with-fetch.
Note that unlike the examples above, the names of the parameters used by the API all end with colons. For example, name=“Number:”. When I point the form at mockbin, it confirms that the post variable names do indeed all end with colons.
<form action="https://mockbin.com/request" method="post">
Number
<input type=text name="Number:" value="5">
<br/>
Parity
<select name="Parity:">
<option value=1>Odd</option>
<option value=2 selected>Even</option>
</select>
<input type=hidden name="Secret:" value="code">
<br/>
<input type="submit" value="Submit">
</form>
When I post to the actual site instead of mockbin, the response is a list of 3D integer coordinates formatted as sets of 3 integers on each line as shown here:
<body bgcolor="#ffffff">
<pre>
-1 -1 -2
1 -1 -2
0 0 -2
-1 1 -2
1 1 2
</pre>
</body></html>
I have two questions:
- How do I post the correct variable names (including the trailing colons) using d3 as in the examples.
- Is d3.dsv or d3.text a reasonable tool to parse the result? If so, can you provide an example of using either of them to generate a data set from the post result? If not, can you suggest an alternative approach?
Thanks