Skip to main content

y.api

Building the y-api container image

1. Clone the repository ssh://git@git.safedns.com:2224/dnsnode/y-api-stat-safe.git 2. Go to the cloned directory, and open the source file yapi.c in a text editor.
3. In the #define USER_LOGIN "test_cdk" line, replace test_cdk with the customer's login.
4. In the #define USER_PASSWD "test_cdk" line, replace test_cdk with the customers's password.
5. Save the changes and close the yapi.c file
6. Build the image with the command sudo docker build -t y-api:1
7. Verify that the image was built with sudo docker image ls

REPOSITORYTAGIMAGE IDCREATEDSIZE
y-api1d52e9648380d26 seconds ago503MB

8. Save the image to the archive with the command sudo docker save y-api:1 | gzip > y_api.tar.gz
9. Send the y_api.tar.gz archive to the customer.


About y-api service

The service provides domain categorization services and can be used both locally and in a distributed system. In the latter case, the speed of receiving a response decreases due to network delays.

Domain categorization requests are made using the HTTP 1.1 protocol. The service counts requests for successfully categorized domains and unknown domains, which are reflected in the counter_cat and counter_unknown_cat counters, respectively. These counters are reset 24 hours after the start of the docker container. The values of both counters can be obtained via an HTTP 1.1 request.

A stable connection to the Internet is required for the uninterrupted operation of the service:

  • loading the database and updating it
  • sending counter_cat and counter_unknown_cat values
  • sending additional information about the instance with the container

Stats are sent every 5 minutes.


Using y-api service

Starting the service

1. Install docker.
2. Load the archive with the container image with sudo docker load -i y_api.tar.gz 3. Run the image in the docker subnet.
    3.1 Alternatively, create a separate subnet
          sudo docker network create --driver=bridge --subnet=193.33.33.0/24 y-api-net
          and run the container
          sudo docker run -it -d --net y-api-net --ip 193.33.33.33 y-api:1

4. Check the service with curl http://193.33.33.33/qwerty.com

Service response: {"category": [36, 49], "bad": false, "category_name": ["Education", "Computers & Internet"]}

ATTENTION! The request counter is sent every 5 minutes. Check time must be shorter so the data is not sent to the statistics server for billing.

Logging is done to stdout and stderr.

The supported request is GET.


Request examples

Request

Answer

curl -v http://193.33.33.33/qwerty.com

< HTTP/1.1 200 OK

< Content-type: application/json

< Connection: keep-alive

* no chunk, no close, no size. Assume close to signal end

<

* Closing connection 0

{"category": [36, 49], "bad": false, "category_name": ["Education", "Computers & Internet"]}

curl -v  http://193.33.33.33/foo

< HTTP/1.1 404 Not Found

< Connection: keep-alive

* Connection #0 to host 193.33.33.33 left intact

curl -v  http://193.33.33.33/stat/

< HTTP/1.1 200 OK

< Content-type: application/json

< Connection: close

<

* Closing connection 0

{"counter_cat": [150002], "counter_unknown_cat": [0]}

curl -v -X POST http://193.33.33.33/qwerty.com

< HTTP/1.1 405 Method Not Allowed

< Content-Type: text/html

< Allow: GET

< Connection: close

* Closing connection 0

If there is no connection with the statistics server or any response from it other than "200 OK".

 

curl -v  http://193.33.33.33/qwerty.com

< HTTP/1.1 503 Service Unavailable

< Content-type: application/json

< Connection: close

<

* Closing connection 0

{"details": "billing failure"}