Application Program Interface (API) is an intermediary code that allows two applications to talk to each other.
This will allow for interaction with the ML code in a server from other networked devices.
For this, we have to write a wrapper application around our ML code, which will unpack the arguments from a request header,
process it and return a response in accordance to some network protocol.
APIs should also allow for getting and updating information from server database.
The requests can either be a single call or a set of repeated calls. Streaming applications would require a continous stream of data to be sent and received.
For eg, real time object detection algorithm run on a video may require a sequence of frames to be sent and received every second. Therefore,
depending on our use case, we can choose betwwen HTTP and Websocket protocols.
HTTP: Half duplex communication. Both client and server cannot send information simultaneously to each other. Client sends a request
with one of these headers : GET, POST, DELETE, UPDATE, CREATE. An API which can process these kinds of requests are called
REST APIs. Python library - DjangoRestFramework, has all the routines to process these requests and pack the response with
Django (one of the production-grade web frameworks). If you are using a different web framework, you may have to resort to standard python calls and do a little bit additional coding.
Websocket Upgrades HTTP to full duplex mode. Data is transfered in binary format. Both client and server can transfer information simultaneously.
After an initial handshake with HTTP headers, connection is established and both client and server become free to stream data to each other.
This protocol should be implemented with care, so that it does not block the main application thread.
DjangoChannels library implements this protocol in a reliable way using Async calls from python 3.0