koa-field-checker

1.0.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i koa-field-checker

Weekly Downloads

0

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • joshbeitler