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:

itemvalue
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/createPvNamespaceopen in new window.

2.1 /pv/get

GET
Description:

By passing parameters, you can get status of given key in given namespace

Parameters
NameLocated inDescriptionRequiredSchema
namespacequerynamespace to get statusYesstring
keyquerykey to get status (without this parameter will return all keys under the namespace)Nostring
Responses
CodeDescription
200get status of PV successfully
400bad input parameter
500internal server error

2.2 /pv/create

POST
Description:

By passing parameters, you can create a namespace for PV with an secret

Parameters
NameLocated inDescriptionRequiredSchema
namespacequerynamespace to createYesstring
secretquerysecret is needed when you want to reset/delete the value (default the same as namepsace)Nostring
Responses
CodeDescription
200create namespace of PV successfully
400bad input parameter
500internal 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
NameLocated inDescriptionRequiredSchema
namespacequerynamespace to be incrementedYesstring
keyquerykey to be incrementedYesstring
Responses
CodeDescription
200increment PV successfully
400bad input parameters
500internal 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
NameLocated inDescriptionRequiredSchema
namespacequerynamespace to be resetYesstring
secretquerysecretYesstring
keyquerykey to be resetYesstring
valuequerynumber of PV to be resetYesinteger
Responses
CodeDescription
200reset PV successfully
400bad input parameters
500internal server error

2.5 /pv/delete

POST
Description:

By passing parameters, you can delete of given key or given namespace

Parameters
NameLocated inDescriptionRequiredSchema
namespacequerynamespace to be deleteYesstring
secretquerysecretYesstring
keyquerykey to be deleteYesstring
Responses
CodeDescription
200delete PV successfully
400bad input parameters
500internal 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)
}