Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d-exclaimation/data-transfer-object
Preferred data transfer object schema
https://github.com/d-exclaimation/data-transfer-object
dto json-schema polyglot
Last synced: 30 days ago
JSON representation
Preferred data transfer object schema
- Host: GitHub
- URL: https://github.com/d-exclaimation/data-transfer-object
- Owner: d-exclaimation
- License: apache-2.0
- Created: 2021-08-07T15:08:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-07T16:47:37.000Z (over 3 years ago)
- Last Synced: 2024-11-07T20:55:05.633Z (3 months ago)
- Topics: dto, json-schema, polyglot
- Language: Scala
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Data-Transfer-Object (Protocol / Standard for REST APIs)
How I would like to format my JSON Responses to take account for errors and predictable schema.
## Features
Predictable response schema to allow for:
- Better Typing on client-side
- Parseable and handleable errors
## AcknowledgementsThis protocol / standard is basically the same as [GraphQL's Response Protocol](https://spec.graphql.org/June2018/#sec-Response-Format).
The basics of this are that JSON Responses should be shaped as
|Field|Type|Description|
|-|-|-|
|data|`Successful object` **or** `null`|The expected return object or null for failure to get any result|
|errors|`Arrays of error object` **or** `null`|Error(s) occurred during the process described as usually string or custom object|This way, it's easier to guess what's going on, parsing a proper JSON Response wouldn't throw an error with bad explanations and instead can directly get the error responses.