Reusable REST API contracts
- Java 21
- Spring Boot 3
implementation("io.opengood.api:rest-api-contracts:VERSION")<dependency>
<groupId>io.opengood.api</groupId>
<artifactId>rest-api-contracts</artifactId>
<version>VERSION</version>
</dependency>Note: See Release version badge above for latest version.
Data contract for deleting data by unique identifier.
Data in JSON format:
name: Name of the data object type in data repositoryid: Unique identifier of a data object to delete from data repository
{
"name": "products",
"id": "82a94d9f-894c-4c00-ba40-a36e8f55f842"
}Data contract containing action response for DeleteDataRequest.
Other contracts used:
OperationState
Data in JSON format:
state: State of requestSUCCESSorFAILEDmessage: Textual message providing context for response
{
"state": "SUCCESS",
"message": "Data deleted"
}Data contract for retrieving data by unique identifier.
Data in JSON format:
name: Name of the data object type in data repositoryid: Unique identifier of a data object to retrieve from data repository
{
"name": "products",
"id": "82a94d9f-894c-4c00-ba40-a36e8f55f842"
}Data contract containing data response for GetDataByIdRequest.
Other contracts used:
OperationState
Data in JSON format:
state: State of requestSUCCESSorFAILEDmessage: Textual message providing context for responsedata: Map of key/value pairs representing row of data retrieved from data repository
{
"state": "SUCCESS",
"message": "Data retrieved",
"data": {
"product_id": 1,
"name": "Product 1"
}
}Data contract for retrieving data. Includes filtering, paging, and sorting.
Other contracts used:
FilterRequestFilterParameterFilterTypeFilterConditionPageRequestSortRequestSortParameterSortDirection
Data in JSON format:
name: Name of the data object type in data repositoryfilter: List of parameters representing fields, values, and types in which to filter data from data repositoryparams: Filtering parameters in which to filter dataname: Name of field in which to filter datavalue: Filter value for fieldtype: Filter type for fieldEQUALSperforms equality filter on fieldCONTAINSperforms contains filter on field
condition: Filter condition for fieldANDcreates an and condition for fieldORcreates an or condition for field
page: Pagination parameters in which to retrieve a page of dataindex: Current index of page of data to retrievesize: Number of rows of data per page to retrieve
sort: List of parameters representing fields and direction in which to sort data from data repositoryparams: Sorting parameters in which to sort dataname: Name of field in which to sort datadirection: Sort direction of fieldASCsorts field in ascending orderDESCsorts field in descending order
{
"name": "products",
"filter": {
"params": [
{
"name": "product_name",
"value": "Product",
"type": "CONTAINS",
"condition": "AND"
}
]
},
"page": {
"index": 0,
"size": 2
},
"sort": {
"params": [
{
"name": "product_name",
"direction": "ASC"
}
]
}
}Data contract containing data response for GetDataRequest.
Includes page and record data.
Other contracts used:
OperationStatePageDataPageStateRecordData
Data in JSON format:
state: State of requestSUCCESSorFAILEDmessage: Textual message providing context for responsepages: Object containing information about page datastate: State of pageNONEorPAGINATEDindex: Current index of page of data retrievedsize: Number of rows of data in current page retrievedcount: Total number of pages in dataset
records: Object containing information about record datatotal: Total number of records in dataset
data: Array containing map of key/value pairs representing row(s) of data retrieved from data repository
{
"state": "SUCCESS",
"message": "Data retrieved",
"pages": {
"state": "PAGINATED",
"index": 0,
"size": 2,
"count": 1
},
"records": {
"total": 2
},
"data": [
{
"product_id": 1,
"name": "Product 1"
},
{
"product_id": 2,
"name": "Product 2"
}
]
}Data contract for saving data.
Data in JSON format:
name: Name of the data object type in data repositorydata: Array containing map of key/value pairs representing row(s) of data to save to data repository
{
"name": "products",
"data": [
{
"name": "Product 1"
},
{
"name": "Product 2"
}
]
}Data contract containing action response for SaveDataRequest.
Other contracts used:
OperationState
Data in JSON format:
state: State of requestSUCCESSorFAILEDmessage: Textual message providing context for responsedata: Array containing map of key/value pairs with generated unique identifier(s) representing row(s) of data saved to data repository
{
"state": "SUCCESS",
"message": "Data saved",
"data": [
{
"product_id": 1,
"name": "Product 1"
},
{
"product_id": 2,
"name": "Product 2"
}
]
}