Skip to content

Unify API form and input validation #27

Open
@sbcgua

Description

@sbcgua

For the API response shape I propose to have something like below. I know might look a bit over engineering for the existing functionality but general API shape is something that is very difficult to change after :)

// for success
{ success: 1, payload: any }
// for error
{ success: 0, error: { message: "Wrong API call", detail: any } }
  • payload can be of any shape (depending on the specific endpoint)
  • error detail - will probably be either array with errors, or object shape similar to request with errors instead of data attrs

Input validation, a bit in doubts:

  1. just ignore for now (i don't like , this is a ground concept)
  2. use some of standard libs. One is very typescript friendly - https://www.npmjs.com/package/class-validator - but looks a bit bloated for me, and requires classes instead of interfaces which imho corrupts the beauty of TS
  3. Use https://github.com/koorchik/js-validator-livr - a very lightweight, descriptive approach, no dependencies. Used it before, no issues (and I know the author - not sure if it is + or - - but they support and use it quite intesively so it does not go anywhere ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions