Skip to content

Instantly share code, notes, and snippets.

@edofic
Created May 6, 2023 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edofic/7c6fc369ef960315422914e946f4854b to your computer and use it in GitHub Desktop.
Save edofic/7c6fc369ef960315422914e946f4854b to your computer and use it in GitHub Desktop.
htmx + mock requests = SPA?
<!DOCTYPE html>
<html>
<head>
<title>Hello Page</title>
<script src="https://unpkg.com/htmx.org@1.9.2"></script>
<script src="https://unpkg.com/mock-requests@1.3.2/index.js"></script>
<script language="javascript">
MockRequests.setDynamicMockUrlResponse('/ui/button',
{
dynamicResponseModFn:
function (request, response, parameters) {
console.log("A mock request was made: ", request, response, parameters)
return "hello"; // hardcoded here but full request is available for dynamically generating
},
usePathnameForAllQueries: true
});
</script>
</head>
<body>
<h1>Hello</h1>
<button hx-get="/ui/button" hx-swap="afterend">Load</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment