Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Express Typescript Prevent Unwanted Data In Post Request

the post request has content_Name,content_Type, content_Json.

Those are the field that should be sent, but if i add a property ill be able to send a request with an unwanted datafield how can i prevent that:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

DTO:

content_name,
content_type,
Content_json,

Json Request (Example) sent

{
  "this_field_shouldnt_be_available" : "Zebb"
}

Request received

{
  "this_field_shouldnt_be_available" : "Zebb",
  content_name: null,
  content_type: null,
  Content_json: null
}

How can I have an exception to use a "DTO" to only allow the valid data
is it possible without schema? just comparing to DTO?

>Solution :

You can add a middleware with a validation to verify each property key that must exist in the DTO, and then validate the quantity of keys of the DTO assuring that it is not greater than the keys you set to be there

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading