amforeas
amforeas copied to clipboard
Add a way for JSON requests to specify the format
The idea is to allow different JSON formats which can be used with different REST clients.
The default format is:
{
"success":true,
"status":"OK",
"rows":[
{
"roi":0,
"cells":{
"birthday":"1982-12-13",
"name":"foo",
"id":0,
"lastupdate":"2020-05-08T21:17:21.993+02:00",
"credit":32.50,
"age":30
}
}
],
"resource":"users",
"pagination":{
"page":1,
"size":6,
"pages":1,
"total":6
}
}
To allow this, we can either use:
- a map JSON file set with configuration
- During runtime with a POST endpoint which receives the format JSON data.
- Allow GET endpoints to accept POST requests with the format JSON data.
The format data would look like:
{
"formats": [
{
"resource": "users",
"meta": {
"success": true,
"status": false,
"pagination": true
},
"model": {
"id": "number",
"name": "string",
"birthday": "dd/MM/yyyy",
"credit": "number"
}
},{
"resource": "cars",
"meta": null,
"model": {
"id": "number",
"maker": "string",
"lastUpdate": "ddMMyyyyhhmmss"
}
}
]
}
A response from users
then would be formatted as:
{
"success":true,
"pagination":{
"page":1,
"size":6,
"pages":1,
"total":6
},
"entities": [
{
"id":0,
"name":"foo",
"birthday":"13/12/1982",
"credit":32.50
}
]
}
And a response from cars
(with no metadata) would look like:
{
"id":0,
"maker":"foo",
"lastUpdate":"13121982040130"
}