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 requestSUCCESS
orFAILED
message
: 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 requestSUCCESS
orFAILED
message
: 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:
FilterRequest
FilterParameter
FilterType
FilterCondition
PageRequest
SortRequest
SortParameter
SortDirection
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 fieldEQUALS
performs equality filter on fieldCONTAINS
performs contains filter on field
condition
: Filter condition for fieldAND
creates an and condition for fieldOR
creates 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 fieldASC
sorts field in ascending orderDESC
sorts 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:
OperationState
PageData
PageState
RecordData
Data in JSON format:
state
: State of requestSUCCESS
orFAILED
message
: Textual message providing context for responsepages
: Object containing information about page datastate
: State of pageNONE
orPAGINATED
index
: 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 requestSUCCESS
orFAILED
message
: 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"
}
]
}