question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validator Middleware

See original GitHub issue

I have an idea, “Validator Middleware”.

I plan that I’ll make it with validator.js, which is used in express-validator. So, it will depend on the external library, which will be a “third-party” middleware.

The express middleware is helpful, but it’s a bit fat, and it seems not too easy to implement. And “just do porting” is not like Hono. I want to make the “Validator Middleware” simpler than the express middleware. Below is the synopsis that on my head now:

const app = new Hono()

app.use(
  '/',
  validator((v) => [
    {
      rule: v.isAlpha,
      field: 'query',
      name: 'q',
    },
  ])
)

app.get('/', (c) => {
  const res = validatorResult(c)
  return c.json(res)
})

export default app

I’ll try to build it on github.com/honojs/validator repository. So if it’s ready, please take a look!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
digitalmiocommented, Aug 3, 2022

Hey, AJV might be a good option, I would also check what library Fastify is using. I’m going on holiday soon, will be able to take a look into this in about week and a bit.

0reactions
yusukebecommented, Aug 7, 2022

Hi there! especially @metrue and @usualoma .

I’m creating “Validator Middleware” and almost done:

https://github.com/honojs/validator/tree/develop

This is what I consider to be the Ideal API. I would like to go with this, but if you must have an opinion, please let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation middlewares - express-validator
Creates a validation chain for one or more fields. ... Creates a middleware instance that will ensure at least one of the given...
Read more >
express-json-validator-middleware - npm
An Express middleware to validate requests against JSON Schemas. Latest version: 3.0.1, last published: 7 months ago.
Read more >
A Clean Approach to Using Express Validator
Express validator is one of the many npm packages for validating a ... as you may deem fit and then chain it with...
Read more >
PayU/openapi-validator-middleware - GitHub
openapi-validator-middleware ... This package provides data validation within an Express, Koa or Fastify app according to a Swagger/OpenAPI definition. It uses ...
Read more >
How to use Express Validator | Getting Started with Express ...
Express-validator is an express middleware that provides us with validation and sanitization functions. Actually, Express validator is built on top of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found