Open lukasturcani opened 1 month ago
@lukasturcani It sounds like a good plan. I have have just couple of comments.
GET /api/v2/auto-experiments/{exp_id} - get the data for experiment {exp_id}
but if you would have use for it than feel free to include it. ?datasetName=A,B,C,D
Legacy data switch was added later and current solution is a bit slap&dash. I think what you propose could work. We could laso create a separate endpoint but that could involve quite a bit of code duplication. So, your plan is probably better.
Happy to discuss further if necessary.
Figured I'd make a tracking issue here to document the design of the v2 API and get feedback as early as possible.
The goal for the new API to be RESTful, which should result in logic on both the backend and frontend being made simpler. By RESTful I mean that the API will be
API Design
Resources will be organized as flat as possible. Each resource has a single type. For example, auto and manual experiments have different fields relevant to each kind of experiement, as a result they correspond to different types and are handled by different resources. Nested path should be reserved for
GET /blog/{blog_id}/comments
GET /authors/{author_id}/books
Suggested routes
GET /api/v2/auto-experiments
- get the data of all auto experimentsGET /api/v2/auto-experiments/{exp_id}
- get the data for experiemt{exp_id}
GET /api/v2/auto-experiments/{exp_id}/raw-data
- get the zip file of experiment{exp_id}
GET /api/v2/manual-experiments
- get the data of all manual experimentsGET /api/v2/manual-experiments/{exp_id}
- get the data of experiment{exp_id}
GET /api/v2/manual-experiments/{exp_id}/raw-data
get the zip file of experiment{exp_id}
Query Parameters
Query parameters should act as simple filters. For example
GET /api/v2/auto-experiments?solvent=A,B&user=C,D
will return all auto experiments where the sovlent is A or B AND user is C or D. Results are returned unsorted unless asort
(+ an optionalorder
) parameters are supplied for exampleGET /api/v2/auto-experiments?solvent=A,B&user=C,D&sort=title&order=asc
Pagination is also supported by query parameters
GET /api/v2/auto-experiments?offset=10&limit=20
Examples
There is no pressing need for the web frontend to actually move onto the v2 api. However, I've selected two examples from the frontend to show how communication with the backend can be made simpler (hopefully!) under the new API.
Experiment table
If using the new API I expect the frontend could display the table of experiments in the following way
GET /api/v2/bruker-datasets?offset=X&limit=20
whereX = pageNumber * 20
GET /api/v2/auto-experiments?datasetName=A,B,C,D
the
bruker-dataset
endpoint can be handled by the backend by returning all unique values ofExperiment.datasetName
it is worth noting that in this example we are adding complexity to the frontend while reducing it for the backend. currrently the backend does the heavy-lifting with regard to joining datasets to experiment and interpreting query parameters. By taking this trade-off we gain re-usability of our backend because the endpoints are less opinionated and do fewer things, and our individual endpoints become cheaper as each call does less (eg. you sort only when asked to)
In addition even though the frontend will need to do more work, the work its doing should be more clear and linear than the code currently in the backend.
Legacy Data
Currently the legacyData query parameter does not act as a simple filter. In the v2 api it would be removed. the frontend instead would send different queries depending on if the legacyData switch is toggled.
GET /api/v2/auto-experiments?userId=X
- returns all experimeents associated with user XGET /api/v2/auto-experiments?userId=X&groupId=Y
- return all experiments asosociatd with user X and group Y. the frotend is repsonsible for supplying the id of the users current group