Usage
0. Counter API
This API provides a service about PV and UV, which allows you:
- Create your own namespace with a secret
- Get values of given keys or all of the keys under your namespace
- Automatically initialize and manually increment keys under your namespace
- Reset the value of keys
- Delete keys or waiting to expire after three months
Currently statistics info:
item | value |
---|---|
namespaces | -1 |
keys | -1 |
requests | -1 |
1. Management Panel
1.1 /pv/create
TIP
create your own namespace, normally using domain name.
Request:
*
Response:
1.2 /pv/reset
TIP
reset the given key under your namespace. Of course, with your secret.
Request:
*
*
*
*
Response:
1.3 /pv/delete
TIP
delete the given key under your namespace. Of course, with your secret.
Request:
*
*
*
Response:
1.4 /pv/get
TIP
get keys under a given namespace
Request:
*
Response:
2. API definition
Full documentation could be found here: https://app.swaggerhub.com/apis/plantree/counter/1.0.0#/developers/createPvNamespace.
2.1 /pv/get
GET
Description:
By passing parameters, you can get status of given key in given namespace
Parameters
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
namespace | query | namespace to get status | Yes | string |
key | query | key to get status (without this parameter will return all keys under the namespace) | No | string |
Responses
Code | Description |
---|---|
200 | get status of PV successfully |
400 | bad input parameter |
500 | internal server error |
2.2 /pv/create
POST
Description:
By passing parameters, you can create a namespace for PV with an secret
Parameters
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
namespace | query | namespace to create | Yes | string |
secret | query | secret is needed when you want to reset/delete the value (default the same as namepsace) | No | string |
Responses
Code | Description |
---|---|
200 | create namespace of PV successfully |
400 | bad input parameter |
500 | internal server error |
2.3 /pv/increment
POST
Description:
By passing parameters, you can increment PV by 1 of given key in given namespace (will initialize automatically)
Parameters
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
namespace | query | namespace to be incremented | Yes | string |
key | query | key to be incremented | Yes | string |
Responses
Code | Description |
---|---|
200 | increment PV successfully |
400 | bad input parameters |
500 | internal server error |
2.4 /pv/reset
POST
Description:
By passing parameters, you can reset PV of given key in given namespace with given value
Parameters
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
namespace | query | namespace to be reset | Yes | string |
secret | query | secret | Yes | string |
key | query | key to be reset | Yes | string |
value | query | number of PV to be reset | Yes | integer |
Responses
Code | Description |
---|---|
200 | reset PV successfully |
400 | bad input parameters |
500 | internal server error |
2.5 /pv/delete
POST
Description:
By passing parameters, you can delete of given key or given namespace
Parameters
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
namespace | query | namespace to be delete | Yes | string |
secret | query | secret | Yes | string |
key | query | key to be delete | Yes | string |
Responses
Code | Description |
---|---|
200 | delete PV successfully |
400 | bad input parameters |
500 | internal server error |
3. Example
3.1 Using axios
try {
const response = await axios.get("https://api.counter.plantree.me/pv/get?namespace=mysite.com&key=index.html");
if (response.status === 200 && response.data.code === 0) {
console.log(response.data);
}
} catch (error) {
console.log(error)
}