<p>Namespaces are meant to avoid name collisions. You may specify a namespace during the creation of a key. Its recommend use the domain of the application as namespace to avoid collision with other websites.<br>If the namespace is not specified the key is assigned to the <code>default</code> namespace. If your key resides in the default namespace you don't need to specify it.</p>
<h2>Endpoints</h2>
<p>
All requests support <ahref="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"target="_blank">cross-origin resource sharing</a> (CORS) and SSL.<br>
You can use <ahref="https://en.wikipedia.org/wiki/JSONP">JSONP</a> sending the callback parameter. JSONP requests will never fail, they will include the HTTP code in the response.<br>
Also a 1x1 GIF image is supported sending <code>?img</code>.
</p>
<p>Base API path: <ahref="https://api.countapi.xyz"target="_blank">https://api.countapi.xyz</a></p>
<p>In the case of a server failure, the API will send:</p>
<p>Set the value of a key. Optionally specify the namespace. The key <b>must</b> be created with <code>enable_reset</code> set to <code>1</code> (true).</p>
<p>This endpoint will return the previous value before the assignation.</p>
<p>Updates a key with <code>+/- amount</code>. Optionally specify the namespace. The <code>amount</code><b>must</b> be within <code>update_lowerbound</code> and <code>update_upperbound</code> specified during the creation of the key.</p>
<preclass="success"><ahref="https://api.countapi.xyz/update/test?amount=5"target="_blank">https://api.countapi.xyz/update/test?amount=5</a> (value was 42)
⇒ 200 { "value": 47 }
<ahref="https://api.countapi.xyz/update/mysite.com/test?amount=-7"target="_blank">https://api.countapi.xyz/update/mysite.com/test?amount=-7</a> (value was 53)
⇒ 200 { "value": 46 }</pre>
<preclass="fail"><ahref="https://api.countapi.xyz/update/outofrange?amount=3"target="_blank">https://api.countapi.xyz/update/outofrange?amount=3</a> (value was 47, update_upperbound=2)
<p>An easier way to track incrementing by one keys. This endpoint will create a key if it doesn't exists and increment it by one on each subsequent request. Optionally specify a namespace.<br>The key created has the following properties:</p>
<ul>
<li><code>enable_reset</code> to <code>0</code> (false)</li>
<li><code>update_lowerbound</code> to <code>0</code></li>
<li><code>update_upperbound</code> to <code>1</code></li>
</ul>
<p>Effectively making the key only incrementable by one.</p>
<preclass="success"><ahref="https://api.countapi.xyz/hit/mysite.com/visits"target="_blank">https://api.countapi.xyz/hit/mysite.com/visits</a> (value was 35)
⇒ 200 { "value": 36 }
<ahref="https://api.countapi.xyz/hit/nonexisting"target="_blank">https://api.countapi.xyz/hit/nonexisting</a> (key is created)
⇒ 200 { "value": 1 }</pre>
<h3class="endpoint">/create</h3>
<p>Creates a key.<br>All parameters are optional</p>
<table>
<thead>
<tr>
<th>name</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td>New UUID</td>
<td>Name of the key</td>
</tr>
<tr>
<td>namespace</td>
<td>default</td>
<td>Namespace to store the key</td>
</tr>
<tr>
<td>value</td>
<td>0</td>
<td>The initial value stored</td>
</tr>
<tr>
<td>enable_reset</td>
<td>0</td>
<td>Allows the key to be resetted with <b>/set</b></td>
</tr>
<tr>
<td>update_lowerbound</td>
<td>-1</td>
<td>Restrict update to not subtract more than this number. This number <b>must</b> be negative or zero.</td>
</tr>
<tr>
<td>update_upperbound</td>
<td>1</td>
<td>Restrict update to not add more than this number. This number <b>must</b> be positive or zero.</td>
</tr>
</tbody>
</table>
<preclass="info">Note about <b>expiration</b>: Every time a key is updated its expiration is set to <b>6 months</b>. So don't worry, if you still using it, it won't expire.</pre>
<preclass="info"id="format">Keys and namespaces must have at least 3 characters and less or equal to 64. Keys and namespaces must match: <b>^[A-Za-z0-9_\-.]{3,64}$</b></pre>
<preclass="fail"><ahref="https://api.countapi.xyz/create?name=alreadycreated"target="_blank">https://api.countapi.xyz/create?name=alreadycreated</a> (the key already existed)