Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request, response types, values, Validators should be exported by back-end, maximally #30

Open
sanjarcode opened this issue Mar 4, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@sanjarcode
Copy link
Member

  • Yesterday, I wrote some Ruby (Rails) code just because request keys that were decided for an API differed from the column name (which Rails defaults to for request keys).

  • This mapping code was non-trivial, since one has to not reset something if the request doesn't have the key (think undefined vs null in JS). - Also, the form used on the frontend had a set of generic validators, for showing wrongly entered values. I had to add a custom validator if value was 'oneOf' a given array of fixed values.


  • at a discussion during the backend code review, the lead backend engineer suggested the changes were cosmetic, perhaps useless. So the team leads got together and decided to use ENUMS on the frontend whose name matched the decided keys but values would match the BE column names exactly. The PR, branch is now useless.

I thought this was a stupid way to code, atleast if you own both the server and client app.

  • The backend has the strongest validation of all, since it ingests data.
  • the frontend validations depend directly on backend validations. Of course, how the UI can be decided in the frontend code.

So, if the backend could just generate a "type" file with

  1. key names
  2. value type
  3. Possible values
  4. Validators to be used by the front-end (if calculable directly, i.e. can be checked without database lookup, atleast)

This would solve a lot of communication tasks, and cosmetic mappings.

@sanjarcode sanjarcode self-assigned this Mar 4, 2023
@sanjarcode
Copy link
Member Author

TypeScript is a tool that solves one part of this problem - a real programming language to enforce and specify types and values.

Unsolved:

  • The exportability from the backend, of such file.
  • excluding directly incalculable validators.
  • how to do this if request and response are too "serialised" (different) from actual models/columns

@sanjarcode sanjarcode added the enhancement New feature or request label Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant