hydrus is a core part of the HydraEcosystem. It is the server which powers Hydra-based API Docs.
We are going to see the main steps hydrus performs when it is given an API doc and has to start the server:
- As the given API doc is a python
dict,hydrususes thehydra-python-corelibrary to parse it. Therefore all the heavy lifting of parsing the API doc is handled by the core library. The core library returns a convinentapidocobject whichhydrususes further. The core library returns an expanded API doc.The
apidocobject exposes all the relevant details of the given API doc in a nice API. For example, we can get the all parsed classes by just doingapidoc.parsed_classesor we can get all collections by doingapidoc.collections. - After we have the
apidocobject, the next big task forhydrusis to setup the database. The schema for the database ofhydrusis specific to the given API doc. That means it convinently makes a database architecture which optimizes for the given API doc. The overview of the process of making a database fromapidocobject is:
-
Go through all the parsed classes (
apidoc.parsed_classes) and all the collections (apidoc.collections) and make a table for each.Parsed classes is the set of all classes in the API doc for which a database table is necessary. This just means all the classes in API doc except the classes defining
hydra:Collection(@idishttp://www.w3.org/ns/hydra/core#Collection),hydra:Resource(@idishttp://www.w3.org/ns/hydra/core#Resource) and the EntryPoint class. -
For a parsed class, the columns are all the properties in
supportedPropertyfor that class in the API doc. These can be found fromapidoc.parsed_classes['class_name']['class'].supportedProperty. If any of the property is referring to another class in the same API doc, that column will be treated as a foreign key to that class. Therefore that column will store theid(primary key) of the other table. For any other general property, there will just be a simple column for that. If the property is ahydra:Link, that will not be treated as a foreign key because its a link, the duty of linking falls on the client rather that the server. -
The table for a collection is slightly different from a parsed_class. Any collection will have only 4 columns. Those are
id(primary key),members(this is used for storing theidof the instance of the class that the collection manages),collection_idwhich is the id for any collection the user creates andmember_typewhich is used to store the@typeof the member.A collection is defined as a "set of somehow related resources".
- After the database is made,
hydruscreates a Flask app. It enables required properties like authentication, pagination, etc and then starts the server.
It might be easier to understand what we discussed above if we could see a ER diagram for a Hydra API Doc. So, let us take the sample Drone API Doc as our example. The ER diagram for the database generated for this Hydra doc can be found here.