# y-api

#### 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.

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.

The performance of the y-api service varies approximately from 70k to 150k requests per second. The performance depends on the number of domains and threads addressing the y-api. It operates based on a parallel server architecture, where a thread is created upon the arrival of a request.

---

#### 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`

<p class="callout info">193.33.33.33 is an example, you can use any other network.</p>

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

<p class="callout warning">**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.</p>

Logging is done to **stdout** and **stderr**.

The supported request is **GET**.

---

##### Request examples

<table id="bkmrk-%D0%97%D0%B0%D0%BF%D1%80%D0%BE%D1%81-%D0%9E%D1%82%D0%B2%D0%B5%D1%82-curl--v" width="100%"><tbody><tr><td style="width: 50.5562%;" width="321">**Request**

</td><td style="width: 49.4438%;" width="321">**Answer**

</td></tr><tr><td style="width: 50.5562%;" width="321">curl -v http://193.33.33.33/qwerty.com

</td><td style="width: 49.4438%;" width="321">&lt; HTTP/1.1 200 OK

&lt; Content-type: application/json

&lt; Connection: keep-alive

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

&lt;

\* Closing connection 0

{"category": \[36, 49\], "bad": false, "category\_name": \["Education", "Computers &amp; Internet"\]}

</td></tr><tr><td style="width: 50.5562%;" width="321">curl -v http://193.33.33.33/foo

</td><td style="width: 49.4438%;" width="321">&lt; HTTP/1.1 404 Not Found

&lt; Connection: keep-alive

\* Connection #0 to host 193.33.33.33 left intact

</td></tr><tr><td style="width: 50.5562%;" width="321">curl -v http://193.33.33.33/stat/

</td><td style="width: 49.4438%;" width="321">&lt; HTTP/1.1 200 OK

&lt; Content-type: application/json

&lt; Connection: close

&lt;

\* Closing connection 0

{"counter\_cat": \[150002\], "counter\_unknown\_cat": \[0\]}

</td></tr><tr><td style="width: 50.5562%;" width="321">curl -v -X POST http://193.33.33.33/qwerty.com

</td><td style="width: 49.4438%;" width="321">&lt; HTTP/1.1 405 Method Not Allowed

&lt; Content-Type: text/html

&lt; Allow: GET

&lt; Connection: close

\* Closing connection 0

</td></tr><tr><td style="width: 50.5562%;" width="321">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

</td><td style="width: 49.4438%;" width="321">&lt; HTTP/1.1 503 Service Unavailable

&lt; Content-type: application/json

&lt; Connection: close

&lt;

\* Closing connection 0

{"details": "billing failure"}

</td></tr></tbody></table>