Internal query creation

Started implementing the internal query creation like mentioned in the
diagrams.

The new endpoint for the queries is:
host/tosm/query?