Check request bodies for specific fields
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.editorconfig
.eslintrc.json
.gitignore
LICENSE
README.md
index.js
package.json

README.md

koa-field-checker

Middleware to check a request body for specific fields and generate nicely formatted errors if any are missing. If a field is missing from the input list, a 401 Bad Request will be generated, otherwise the middleware will simply pass through.

Installation

yarn add koa-field-checker

Example

import Koa from 'koa'
import Router from 'koa-router'
import fields from 'koa-field-checker'

const app = new Koa()
const router = new Router()

app
  .use(router.routes())
  .use(router.allowedMethods())

router.get('/:id', fields(["username", "password"]), function async (ctx, next) {
  ...
})

License

Copyright 2017 Joshua Beitler

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.