examples/interceptor.html
<!DOCTYPE html>
<html>
<head>
<title>bock interceptor</title>
<script src="../bock.js"></script>
<script src="//cdn.rawgit.com/lil-js/http/0.1.15/http.js"></script>
<script type="text/javascript">
// configure the mock request
bock('http://httpbin.org')
.get('/status/204')
.replyWithBody('Hello World')
.replyWithHeaders({ 'Content-Type': 'text/plain' })
.delay(1000)
.reply(200)
function sendSampleRequest() {
lil.http('http://httpbin.org/status/204', function (err, res) {
console.log('Response status is', res.status, 'instead of 204')
console.log('and response body is:', res.data)
})
}
</script>
</head>
<body>
<p>Open the DevTools console</p>
<a href="#" onclick="sendSampleRequest()">Send sample request</a>
</body>
</html>