More tm-http-request examples

I wrote a reusable, parameterized tiddler which renders a button to send an HTTP request and displays the response. The url is the only required parameter. The HTTP method and body can optionally be supplied. You can try it out at this demo share site link.

In addition to the parameterized tiddler, I include 10 examples. Most of them make use of the excellent https://httpbin.org website to exercise various HTTP features.

For convenience, here are the 10 examples:

|!http request|!notes|
|<$transclude $tiddler="http-request template" url="https://httpbin.org/get"/>|simple GET|
|<$transclude $tiddler="http-request template" url="https://httpbin.org/post" method="POST" body='{"foo": "bar"}'/>|simple POST|
|<$transclude $tiddler="http-request template" url="https://httpbin.org/post#get"/>|GET a URL which expects only POST|
|<$transclude $tiddler="http-request template" url="https://httpbin.org/delay/2"/>|Delayed response to ensure the intermediate Pending state can be seen|
|<$transclude $tiddler="http-request template" url="https://httpbin.org/drip?duration=2&numbytes=10&code=200&delay=2"/>|A chunk of the response data will "drip" every 2 seconds. The progress will visibly increase with each chunk.|
|<$transclude $tiddler="http-request template" url="https://httpbin.org/uuid"/>|retrieve a unique ID|
|<$transclude $tiddler="http-request template" url="https://httpbin.org/status/504"/>|Simulate a 504 Gateway timeout response|
|<$transclude $tiddler="http-request template" url="https://google.com/"/>|This request will fail due to CORS restrictions (i.e. google.com does not have headers to allow cross-site requests)|
|<$transclude $tiddler="http-request template" url="https://192.0.2.1"/>|According to [[rfc5737|https://datatracker.ietf.org/doc/html/rfc5737]] this is not a routeable address, so the request should time out and fail|
|<$transclude $tiddler="http-request template" url="https://127.0.0.1:12345"/>|Assuming no server is running on the local machine at port 12345, this should fail right away|

Note that the code uses the url to construct the name of the tiddler for storing the response. In order to prevent collisions when two examples use the same url, I append something like #get to the url to ensure it is unique. Anything after # is not sent, so that part will not be seen by the server. It is a workaround to avoid collisions.

2 Likes

Thanks @btheado for helping to enable a broader audience to make use of this potentialy revolutionary new features.