diff --git a/docs/2_worker_tricks/HowTo_atomicCounter.md b/docs/2_worker_tricks/HowTo_atomicCounter.md index 21d562f..105abd7 100644 --- a/docs/2_worker_tricks/HowTo_atomicCounter.md +++ b/docs/2_worker_tricks/HowTo_atomicCounter.md @@ -1,5 +1,9 @@ # HowTo: make an atomic counter using `countapi.xyz`? +This API allows you to create simple numeric counters. Each counter is identified inside a `namespace` with a `key`. + +Keys and namespaces must have at least 3 characters and less or equal to 64. Keys and namespaces must match: **`^[A-Za-z0-9_\-.]{3,64}`** pattern. + ## Prepare yourself 1: make a 64 char long private key To create a unique key, for yourself, on your super safe computer, @@ -21,12 +25,19 @@ Keep the KEY (and possibly also the DOMAIN) a secret. To make a counter on `countapi.xyz`, replace namespace and key with your own values (demo values are `example.com` and `dvAV77q6uaIOSzE_cgq6Bs_q-vojyIglNLW8lWHtiGUuWM03mLCZnaWIqTtlWYhk`). +Use `/create?&` to make new counter. +Specify initial settings by adding optional params +* `value` The initial value stored. +* `enable_reset` Allows the key to be resetted with /set. +* `update_lowerbound` Restrict update to not subtract more than this number. This number must be negative or zero. +* `update_upperbound` Restrict update to not add more than this number. This number must be positive or zero. + `https://api.countapi.xyz/create?namespace=example.com&key=dvAV77q6uaIOSzE_cgq6Bs_q-vojyIglNLW8lWHtiGUuWM03mLCZnaWIqTtlWYhk&update_lowerbound=0&update_upperbound=1&value=64` -Check your counter by looking at its info on countapi.xyz: +Check your counter by looking at its info on countapi.xyz using `/info//`: `https://api.countapi.xyz/info/example.com/dvAV77q6uaIOSzE_cgq6Bs_q-vojyIglNLW8lWHtiGUuWM03mLCZnaWIqTtlWYhk` -You can use the counter by calling: +You can use the counter by calling `/hit//`: `https://api.countapi.xyz/hit/example.com/dvAV77q6uaIOSzE_cgq6Bs_q-vojyIglNLW8lWHtiGUuWM03mLCZnaWIqTtlWYhk` The countapi.xyz returns json data. @@ -62,4 +73,4 @@ addEventListener('fetch', e=>e.respondWith(handleRequest(e.request))); ## References -* [countapi.xyz](https://countapi.xyz) \ No newline at end of file +* [countapi.xyz](https://countapi.xyz)