add web widget example

This commit is contained in:
sophie 2022-09-18 00:39:52 +01:00
parent 1adcd2eada
commit b73d8a010c
1 changed files with 16 additions and 2 deletions

View File

@ -1,8 +1,22 @@
# viewcounter
ethical view counting api
## usage
### requesting view counts
## examples
### embedded view counter
```html
<div id="view-count"></div>
<script>
var req = new XMLHttpRequest();
req.addEventListener("load", function () {
document.getElementById("view-count")
.innerHTML = "<b>page views</b> " + JSON.parse(this.responseText).views;
});
req.open("POST", "/viewcounter");
req.send("/index.html");
</script>
```
### requesting all view counts
sending a GET request will return a json object with all the stored viewcounts
```sh
$ curl localhost:8001/viewcounter