-
Notifications
You must be signed in to change notification settings - Fork 3
Front End and API
This page explains the functionalities of the front end web application, contained
in dp-front
. The web app is built on Flask + Jinja2. It uses PostgreSQL as the database engine and Redis + Celery for background tasks management.
Corset functionalities are, most of them, asynchronous. This means that for every view, at least two endpoints are defined: one to render the view to the user and another one to perform business logic. The view will make a request to the business logic endpoint asynchronously.
This web app displays data by hydrating the rendered view. This means that, except for a few cases, the view is rendered empty and then it is filled with contents retrieved with JavaScript.
The business logic is synchronous but executed in asynchronous Gunicorn workers.
The API connects the back-end functionalities with the front-end. Since the back-end
server is not necessarily open to public connections, the front-end server
works as a proxy for /api
requests. Requests sent to the /api
endpoint
will be proxied to the back-end server, where the API lives.
The available API endpoints are described in the following table.
Resource | Method | Request body | Response code | Response body | |
---|---|---|---|---|---|
/search | GET |
base_corpus: int custom_corpus: int search_term: str search_lang: str rows: int field: str |
200 | Results found | SearchResponse |
400 | Non-valid query | ||||
404 | No results | ||||
/search/history | GET |
limit: int |
200 | Results found | SearchRequest[] |
400 | Non-valid query | ||||
404 | No results | ||||
/corpora/query | POST |
name: str topic: int size: str download_format: str file: FileStorage source_lang: int target_lang: int collection: int |
201 | Query corpus created | task_id: str |
400 | Non-valid query | ||||
500 | Error while creating query corpus | ||||
/corpora/base | GET | 200 | Results found | BaseCorpus[] | |
400 | Non-valid query | ||||
404 | No results | ||||
/corpora/base/{id} | GET |
preview: bool preview_rows: int preview_start: int |
200 | Base Corpus found | BaseCorpus |
400 | Non-valid query | ||||
404 | No results | ||||
/corsets | POST |
base_corpus: int query_corpus: int |
201 | Query request launched | BaseCorpus |
400 | Non-valid query | ||||
500 | Could not launch Query Request | ||||
/corsets | GET | 200 | Corsets found | QueryRequest[] | |
400 | Non-valid query | ||||
404 | Corsets not found | ||||
/corsets/{query_request_id} | GET |
preview: bool preview_rows: int preview_start: int |
200 | Corset found |
QueryRequest Sentences[] if preview enabled |
400 | Non-valid query | ||||
404 | Corset not found | ||||
/corsets/highlights | GET | 200 | Results found | QueryRequest[] | |
400 | Non-valid query | ||||
404 | Results not found | ||||
/job | GET |
limit: int all: bool |
200 | Results found | QueryRequest[] |
400 | Non-valid query | ||||
404 | Results not found |
Corsets are generated in a Celery task. This allows for parallel corset generation, process monitoring and non-blocking concurrent requests.
The process of generating a corset is as follows:
- User fills the Query form and provides a set of sentences to generate the corset from.
- The user-provided data is sent through the API to the backend.
- The corset is generated inside a Celery task.
- While the corset is being generated, the front-end requests the process status in a certain interval, and displays that status to the user.
- Once the corset is generated, the process is tagged as ready.