``findface-sf-api``
---------------------------------

The ``findface-sf-api`` service implements HTTP API for the FindFace core main functionality such as face detection and face recognition (the mentioned functions themselves are provided by `findface-extraction-api``). It interfaces with the biometric database powered by Tarantool via the ``findface-tarantool-server`` service, as well as with ``findface-extraction-api`` (provides face detection and face recognition) and ``findface-upload`` (provides a storage for original images and FindFace core artifacts). 

To detect a face in an image, you need to send the image in an API request to ``findface-sf-api``. The ``findface-sf-api`` will then redirect the request to ``findface-extraction-api`` for face detection and recognition.

If there is a configured video face detection module in the system (like in FindFace Security), ``findface-sf-api`` also interfaces with the ``findface-facerouter`` service. It receives data of detected in video faces along with processing directives from ``findface-facerouter``, and then executes the received directives, for example, saves faces into a specific database gallery. 

.. note::
   In FindFace Security, ``findface-facerouter`` functions are performed by ``findface-security``.

Functionality:

* HTTP API implementation (face detection and face recognition methods, performed via ``findface-extraction-api``).
* saving face data to the biometric database (performed via ``findface-tarantool-server``),
* saving original images, face thumbnails and normalized face images to an NginX-powered web server (via ``findface-upload``).
* provides interaction between all the FindFace core components.

The ``findface-sf-api`` configuration is done through the ``/etc/findface-sf-api.ini`` configuration file.

.. code::

   listen: 127.0.0.1:18411
   extraction-api:
     timeouts:
       connect: 5s
       response_header: 30s
       overall: 35s
       idle_connection: 10s
     extraction-api: http://127.0.0.1:18666
   storage-api:
     timeouts:
       connect: 5s
       response_header: 30s
       overall: 35s
       idle_connection: 10s
     max-idle-conns-per-host: 20
     shards:
     - master: http://127.0.0.1:8101/v2/
       slave: ''
     - master: http://127.0.0.1:8102/v2/
       slave: ''
     - master: http://127.0.0.1:8103/v2/
       slave: ''
     - master: http://127.0.0.1:8104/v2/
       slave: ''
     - master: http://127.0.0.1:8105/v2/
       slave: ''
     - master: http://127.0.0.1:8106/v2/
       slave: ''
     read_slave_first: false
     max_slave_attempts: 2
     cooldown: 2s
   limits:
     url-length: 4096
     deny-networks: 127.0.0.0/8,192.168.0.0/16,10.0.0.0/8,::1/128,fe00::/8
     body-image-length: 33554432
     allow-return-facen: true
   cache:
     type: memcache
     inmemory:
       size: 16384
     memcache:
       nodes:
       - 127.0.0.1:11211
       timeout: 100ms
       dns_cache_timeout: 1m0s
     redis:
       network: tcp
       addr: localhost:6379
       password: ''
       db: 0
       timeout: 5s
   normalized-storage:
     type: webdav
     enabled: true
     webdav:
       upload-url: http://127.0.0.1:3333/uploads/
       timeouts:
         connect: 5s
         response_header: 30s
         overall: 35s
         idle_connection: 10s
     s3:
       endpoint: ''
       bucket-name: ''
       access-key: ''
       secret-access-key: ''
       secure: true
       region: ''
       public-url: ''
       operation-timeout: 30


When configuring ``findface-sf-api``, refer to the following parameters:

+---------------------------------------------+----------------------------------------------------------------------------------------------------------+
| Parameter                                   | Description                                                                                              |
+=============================================+==========================================================================================================+
| ``extraction-api`` -> ``extraction-api``    | IP address of the ``findface-extraction-api`` host.                                                      |
+---------------------------------------------+----------------------------------------------------------------------------------------------------------+
| ``limits`` -> ``body-image-length``         | The maximum size of an image in an API request, bytes.                                                   |
+---------------------------------------------+----------------------------------------------------------------------------------------------------------+
| ``normalized-storage`` -> ``webdav`` ->     | WebDAV NginX path to send original images, thumbnails and normalized face images to the                  |
|  ``upload_url``                             | ``findface-upload`` service.                                                                             |
+---------------------------------------------+----------------------------------------------------------------------------------------------------------+
| ``storage-api`` -> ``shards`` -> ``master`` | IP address of the ``findface-tarantool-server`` master shard.                                            |
+---------------------------------------------+----------------------------------------------------------------------------------------------------------+
| ``storage-api`` -> ``shards`` -> ``slave``  | IP address of the ``findface-tarantool-server`` replica shard.                                           |
+---------------------------------------------+----------------------------------------------------------------------------------------------------------+