Skip to content

Commit beae3f4

Browse files
committed
Merge pull request #139 from matt-hickford/forms
Add endpoint /forms/post with simple HTML form that submits to /post
2 parents 8da97c4 + 045f0f8 commit beae3f4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

httpbin/core.py

+7
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ def view_cookies(hide_env=True):
291291
return jsonify(cookies=cookies)
292292

293293

294+
@app.route('/forms/post')
295+
def view_forms_post():
296+
"""Simple HTML form."""
297+
298+
return render_template('forms-post.html')
299+
300+
294301
@app.route('/cookies/set/<name>/<value>')
295302
def set_cookie(name, value):
296303
"""Sets a cookie and redirects to cookie list."""

httpbin/templates/forms-post.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
</head>
5+
<body>
6+
<!-- Example form from HTML5 spec http://www.w3.org/TR/html5/forms.html#writing-a-form's-user-interface -->
7+
<form method="post" action="/post">
8+
<p><label>Customer name: <input name="custname"></label></p>
9+
<p><label>Telephone: <input type=tel name="custtel"></label></p>
10+
<p><label>E-mail address: <input type=email name="custemail"></label></p>
11+
<fieldset>
12+
<legend> Pizza Size </legend>
13+
<p><label> <input type=radio name=size value="small"> Small </label></p>
14+
<p><label> <input type=radio name=size value="medium"> Medium </label></p>
15+
<p><label> <input type=radio name=size value="large"> Large </label></p>
16+
</fieldset>
17+
<fieldset>
18+
<legend> Pizza Toppings </legend>
19+
<p><label> <input type=checkbox name="topping" value="bacon"> Bacon </label></p>
20+
<p><label> <input type=checkbox name="topping" value="cheese"> Extra Cheese </label></p>
21+
<p><label> <input type=checkbox name="topping" value="onion"> Onion </label></p>
22+
<p><label> <input type=checkbox name="topping" value="mushroom"> Mushroom </label></p>
23+
</fieldset>
24+
<p><label>Preferred delivery time: <input type=time min="11:00" max="21:00" step="900" name="delivery"></label></p>
25+
<p><label>Delivery instructions: <textarea name="comments"></textarea></label></p>
26+
<p><button>Submit order</button></p>
27+
</form>
28+
</body>
29+
</html>

httpbin/templates/httpbin.1.html

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ <h2 id="ENDPOINTS">ENDPOINTS</h2>
3636
<li><a href="/robots.txt" data-bare-link="true"><code>/robots.txt</code></a> Returns some robots.txt rules.</li>
3737
<li><a href="/deny" data-bare-link="true"><code>/deny</code></a> Denied by robots.txt file.</li>
3838
<li><a href="/cache" data-bare-link="true"><code>/cache</code></a> 200 unless If-Modified-Since was sent, then 304.</li>
39+
<li><a href="/forms/post" data-bare-link="true"><code>/forms/post</code></a> HTML form that submits to <code>/post</code>.</li>
3940
</ul>
4041

4142

0 commit comments

Comments
 (0)