Это видео недоступно.
Сожалеем об этом.

Ajv JSON schema validation

Поделиться
HTML-код
  • Опубликовано: 14 авг 2024
  • 🔥More exclusive content: productioncode...
    Twitter: / _jgoebel
    Website: jangoebel.com
    Blog: productioncode...
    Code: github.com/pro...
    Ajv.js: ajv.js.org
    JSON schema: json-schema.org/
    00:00 introduction to Ajv JSON schema validation
    00:50 Ajv example project walkthrough
    02:20 install ajv and ajv-formats
    03:35 creating and configuring Ajv instance
    05:18 creating a custom Ajv JSON schema
    08:11 creating an Ajv schema validation middleware
    09:56 Ajv errors: preserving the reference
    12:13 making use of Ajv validator in express
    12:50 testing Ajv validation with Postman
    14:11 conclusion
    In this video we cover how to perform JSON validation with Ajv. We use Ajv to validate incoming request payloads and to return a bad request error in case we are missing certain fields or in case certain fields are not formatted correctly.
    We talk about how to set up Ajv with express and we create a custom Ajv schema which we can plug into our express middleware. The Node.js Ajv validator is probably one of the most promising request body validation approaches out there because it makes use of the standardized cross-plattform JSON schema RFC: json-schema.org/

Комментарии • 26

  • @jgoebel
    @jgoebel  3 года назад +12

    What do you think about this video?
    Was the explanation clear?

  • @1arpaxad
    @1arpaxad 2 года назад +2

    amazing explanations. very nice and clean way to handle input validation

    • @jgoebel
      @jgoebel  2 года назад

      Glad it was helpful!

  • @ezhilarasan9910
    @ezhilarasan9910 Год назад +1

    Can I send the sample json data with the request instead using postman?

  • @sakethraman611
    @sakethraman611 3 года назад +1

    Great video, thanks a lot for clearly explaining why the error reference needs to be copied.

    • @jgoebel
      @jgoebel  3 года назад

      thx Saketh 👍

  • @dan-louis
    @dan-louis 2 года назад +1

    Thanks for the video!
    If you are getting a error that says "Cannot set headers after they are sent to the client", you can add an 'else' in front of the 'next()' in validate-dto.js.

    • @jgoebel
      @jgoebel  2 года назад

      this error means that you have basically instructed the server to send a response and shortly after it you are trying to modify the response by adding an additional header

  • @1arpaxad
    @1arpaxad 2 года назад +1

    ajv-sanitizer is also a nice library to use with ajv

  • @thaynabentodasilva3424
    @thaynabentodasilva3424 2 года назад

    Awesome!! The video helped me a lot. Thanks!

    • @jgoebel
      @jgoebel  2 года назад

      Glad it helped!

  • @mohammedaliyaan7130
    @mohammedaliyaan7130 2 года назад

    Thank you soo much, Ajv concept cleared

    • @jgoebel
      @jgoebel  2 года назад

      thx Mohammed 👍

  • @alisawiali70
    @alisawiali70 9 месяцев назад

    Thanke vier mach

    • @jgoebel
      @jgoebel  8 месяцев назад

      you're most welcome

  • @sdfsfsfd437
    @sdfsfsfd437 Год назад

    Is it also possible to use AJV for FRONTEND data validation?

  • @alsjdnfansdfk
    @alsjdnfansdfk 11 месяцев назад

    Nice video, thanks.

    • @jgoebel
      @jgoebel  10 месяцев назад

      Glad you liked it!

  • @1arpaxad
    @1arpaxad 2 года назад

    in the validateDto function, you might want to change "res.status(400).json(errors);" to "return res.status(400).json(errors);" to prevent next being called and immediately return the response to the client

    • @TakingItCasual
      @TakingItCasual 2 года назад

      I get a consistent-return eslint error after implementing your change. Would instead putting the "next();" under an else statement be ideal?

    • @1arpaxad
      @1arpaxad 2 года назад

      @@TakingItCasual can you send your code snippet after the change?

  • @NoName-oh9fh
    @NoName-oh9fh 3 года назад

    А что лучше использовать по вашему опыту для валидаций тела запроса в nodeJS?

    • @jgoebel
      @jgoebel  3 года назад

      this is ultimately a matter of taste. I'd go with some library. Some people use Ajv, others use yup or express-validator. Any of them works. Ajv has the additional advantage that it is standardized

  • @abhs4932
    @abhs4932 3 года назад +1

    Good video

    • @jgoebel
      @jgoebel  3 года назад

      thx abh! 👍

  • @reilwaystation9511
    @reilwaystation9511 2 года назад

    whenever I hear AJV my mind thinks of JAV