Update Implementing Generic CRUD Endpoints authored by Vihar Mamania's avatar Vihar Mamania
---
title: Implementing Generic CRUD Endpoints
---
This doc will help you to configure basic set of CRUD APIs for a particular entity. The APIs which would be exposed by this process would be as follows:-
* Read record using ID - `/ddms/v3/{entityName}/{recordID}`
* Create or update record- `/ddms/v3/{entityName}`
* Delete record using ID - `/ddms/v3/{entityName}/{recordID}`
* Get Versions of record `/ddms/v3/{entityName}/{recordID}/versions`
* Get particular version of record - `/ddms/v3/{entityName}/{recordID}/versions/{versionID}`
# Process
## **Record-Level Consistency Check**
Implement a function to perform record-level consistency validation. This function should accept a single record as input and execute basic sanity checks to determine the validity of the received data. The validation logic will vary across different entities and is required during **Step 3** while configuring the API configuration object.
## **Record ID Constraint**
<span dir="">In `osdu_record_id.py` add a entity specific recordID constraint. This constraint validates the input </span>`recordID`<span dir=""> against a predefined regex pattern configured for the API. It ensures only records with valid IDs are accepted, helping to filter out malformed or non-compliant entries.</span>
## API Configuration
In `api_configuration.py` add a API config object with all details.
```
WellPressureTestRawMeasurementAPI = APIConfiguration(tag = "Well Pressure Test Raw Measurement", entityURI="/wellpressuretestrawmeasurement", entity=Entity.WELLPRESSURETESTRAWMEASUREMENT,record_id_constraint=WellPressureTestRawMeasurementId, record_consistency_check_function=check_well_pressure_test_raw_measurement_consistency)
```
Finally In `wdms_app.py` add the above API object to `ddms_v3_routes_crud_api` list, this would automatically expose the given set of APIs for this entity.
```
ddms_v3_routes_crud_api: list[APIConfiguration] = [
WellPressureTestRawMeasurementAPI
]
```
\ No newline at end of file