2024 - Cyril Bigot, Nicolas Chenche, Stéphane Mabille
API_RDcode is an interface developed in the scope of the RD-Code project to ease the interactions between users and the Nomenclature Pack data and help integration into their information system. The Nomenclature Pack originates from Orphanet and aims at facilitating the implementation of the ORPHAcodes.
This server was built using the Connexion library on top of Flask, and was generated by the swagger-codegen project, according to OpenAPI v3 standards. The API uses Elasticsearch to query the requested data on endpoint's call.
Python 3.5.2+
To run the server, please execute the following from the root directory:
pip3 install -r requirements.txt
python3 wsgi.py
and open your browser to here:
http://localhost:8080/
Mandatory in request header:
- any string for user level curl -X GET "http://api.orphacode.org/.../..." -H "accept: application/json" -H "apiKey: anything"
Gandi.net SFTP 3723642@sftp.sd3.gpaas.net pwd: (cf. Marc Hanauer) 5d...C6 host selected built-in: Python 3.8 MySQL 8.0 You only need to deploy at the host server's root level:
- swagger_server
- media
- (rest of files) For this purpose I create a new branch "deployment" to trim the unnecessary files.
Add gandi as a distant remote
git remote add gandi git+ssh://3723642@git.sd3.gpaas.net/default.git
Push to the remote
git push gandi branch_to_push
Deploy the application of production server
ssh 3723642@git.sd3.gpaas.net deploy default.git branch_to_push
Here you can reload the server and purge the cache, it's also a shortcut to some logs. https://3723642.admin.sd3.gpaas.net/ pwd: (cf. Marc Hanauer) 5d...C6
- Online, the server will call wsgi.py as an entry point, it only reference the main application.
- swagger_server/API_main.py is the Connexion/Flask object you can pass additional options (see Flask documentation).
- Then the application loads the API contract processed by the swagger-codegen. swagger_server/swagger/swagger.yaml
- The User Interface (UI) is generated from swagger_server/template/index.j2 with jinja2 template generator.
- The UI will loads the necessary javascript and CSS property from the swagger-ui python module.
- The images are served from a folder at the root of the online server, meaning at the same directory level than swagger_server, in a folder named media. It is not possible to change the authorizations path for gandihost server so this folder has to be separated from the flask server.
- The media files path must be referenced by "./media/". Thus it will not work directly in development, you can use the special media route for this, comment for production server.
- The API operations are located in the swagger_server/controllers
directory. Their name are generated from the swagger-codegen from the operations
tags defined in the yaml file.
- authorization_controller.py Will handle the apiKey check. (Open for now.)
- query_controller
Collection of functions needed to perform the query with elasticsearch.
Because of the way elasticsearch return result, you need to slightly adjust
the treatment of data.
Depending of the amount of data you expect to return,
you can choose to use:
- single_res for a single result
- multiple_res for a reasonable number of results (N << 10000)
- uncapped_res for an higher number This method will use the "scroll" function of elastic search and will cost more resources. Also contains a function to convert the API response to YAML.
- other controllers
- Controllers define the behavior of the API on endpoint call. Basic use is :
sequenceDiagram
User->>API: endpoint request
API->>Elasticsearch: query
Elasticsearch->>API: response
Note over API: processes data
API->>User: send back answers