API Thoughts & Styles #14
Replies: 2 comments
-
|
Should all error messages follow Pydantic's detail format? Doing so would make it easy for users and the frontend to quickly identify where in the payload such an error occurred. This format was utilized in the original DataManager/AMPAPI to dynamically display those messages in appropriate fields and locations. The format is "detail": [
{
"type": error type like value_error,
"loc": where the error occurred in payload, like [body, sample_top],
"msg": error message,
"input": {input field: input value that caused the error}
}
] |
Beta Was this translation helpful? Give feedback.
-
|
If a table has descriptor tables, like how 'contact' has associated 'email', 'phone', and 'address' tables, adding new records to those descriptor models are done by specifying the descripted table's ID in the payload. For example: POST need to have |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Thoughts on adopting the following API styles? After debate and discussion and consensus I'll write up an ADR:
Goals
Maintain an API that is easy to upkeep, understand, and use.
How
Style
snake-casefor all paths/observation/groundwater-levelinstead of/observation/groundwater_levelor/observation/groundwaterlevelkebab_casefor all query and path parameters/thing/{thing_id}or/thing?thing_id=...?format=query parameter to let the user specify which format they desire.?format=shapefile,?format=csv,?format=geojson/thing/{thing_id}and/thing?thing_id=.../thing?thing_id=1,2,3,4,5Data Validation
The same custom data validations should be performed for both POST and PATCH requests. This is easily achieved by creating a base Validation Pydantic schema from which Create and Update schemas inherit. Since some fields are required for Create and optional for Update schemas, each field validator should set
check_fields=False.e.g.
Database errors, such as foreign key constraints and uniqueness, should be handled by the database, not Pydantic. This minimizes the number of calls made to the database because if Pydantic were used for these data validations extra calls would be made to the database (for every request
nmore database calls would be made wherenare the number of validations performed). try/except clauses should be used to handle these errors and return appropriate error messages.Errors & Empty Data Sets
GET /thing/1should return a 404 error if there is no object with that IDGET/thing?thing_id=1should return an empty set if there is no object with that idGET /thing?thing_id=1,2,3,4,5should return all objects with the valid IDs. No errors should be raised for invalid IDs hereDocumentation
Beta Was this translation helpful? Give feedback.
All reactions