Requests Module Examples

createFetchRequest

Trigger a request below, to see the response information. (the last two image requests might fail if you are viewing this file directly from the file system, due to CORS security settings, but the examples should work when served by a webserver)

trigger request to see result
Should query a JSON API and return a post in the payload Should query a JSON API and return a newly created post with title "foo" and body "bar" in the payload Should query a JSON API and return a patched post with title "foo" in the payload Should query a JSON API and delete a post, which should result in an empty payload Should query a JSON API and return a post as unformatted text in the payload Should query a local image and return its size in the payload Should query a missing local image and return an error response with a null payload Should query a JSON API, but should immediately time out

Change the behaviour of the links above, by changing what kind of fetch is getting used. Usually, "createFetchRequest" uses a ponyfilled XHR-based request, looking and behaving like a native fetch. Using the buttons below, you can define other implementation options

createJsonRequest

Trigger a request below, to see the response information. If the request injects the result into the DOM, have a look at the container below the code area to see inserted nodes.

trigger request to see result
injection target (inspect for details)
Should query a JSON API and return the JSON source Should query a JSON API, append a JSON script to injection target and show the script's content Should query a JSON API, prepend a JSON script in the injection target and show the script's raw content Should query a JSON API, prepend a JSON script before the injection target and show the script's content

RestfulJsonClient

Trigger a request below, to see the response information.

trigger request to see result
Should query a JSON API and return a post in the payload Should query a JSON API and return a newly created post with title "foo" and body "bar" in the payload Should query a JSON API and return a patched post with title "foo" in the payload Should query a JSON API and delete a post, which should result in an empty payload

createJsRequest

Trigger a request below, to see the response information. If the request injects the result into the DOM, have a look at the container below the code area to see inserted nodes.

trigger request to see result
injection target (inspect for details)
Should request a JavaScript, show the script's inline content Should request a JavaScript, append an inline script to the injection target, show the script's inline content and execute the script, resulting in a popup message Should request a JavaScript, insert an inline script before the injection target, show the script's raw content and execute the script, resulting in a popup message Should prepend a sourced JS script in the injection target, show the script's id and execute the script after load, resulting in a popup message

createCssRequest

Trigger a request below, to see the response information. If the request injects the result into the DOM, have a look at the container below the code area to see inserted nodes.

trigger request to see result
injection target (inspect for details)
Should request a stylesheet, show the sheet's inline content Should request a stylesheet, append an inline style to the injection target, show the styles's inline content and apply the sheet to the site Should request a stylesheet, insert an inline style before the injection target, show the styles's raw content and apply the sheet to the site Should prepend a sourced link tag in the injection target, show the link's id and apply the sheet to the site

createHtmlRequest

Trigger a request below, to see the response information. If the request injects the result into the DOM, have a look at the container below the code area to see inserted nodes.

trigger request to see result
injection target (inspect for details)
Should request an HTML document, display whole raw document source Should request an HTML document, show the document's source Should request an HTML document, append the H1 to the injection target, show H1's source Should request an HTML document, insert Ps before the injection target, show the Ps' sources Should request an HTML document, prepend the included H1 and Ps, the combined source of the H1 and Ps

visitUrl

Trigger a request below, result should show the final URL, which was visited.

trigger request to see result
Should request a URL and finish in time Should request a URL, but should immediately run into a timeout Should request a URL with a token and finish in time Should request a URL with a custom token and finish in time