Skip to content

Commit

Permalink
Updated README to reflect change to peerDep. (#10)
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
arb authored and cjihrig committed Jul 12, 2016
1 parent c2f38f1 commit a2eeeb1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

[![Current Version](https://img.shields.io/npm/v/celebrate.svg)](https://www.npmjs.org/package/celebrate)
[![Build Status](https://travis-ci.org/continuationlabs/celebrate.svg?branch=master)](https://travis-ci.org/continuationlabs/celebrate)
[![Dependencies](https://img.shields.io/david/continuationlabs/celebrate.svg)](https://github.com/continuationlabs/celebrate)

[![belly-button-style](https://cdn.rawgit.com/continuationlabs/belly-button/master/badge.svg)](https://github.com/continuationlabs/belly-button)

`celebrate` is an Express middleware function that wraps the [joi](https://github.com/hapijs/joi) validation library. This allows you to use this middleware in any single route, or globally, and ensure that all of your inputs are correct before any handler function. The middleware allows you to validate `req.params`, `req.headers`, `req.query` and `req.body` (provided you are using `body-parser`).

`celebrate` uses ["peerDependencies"](https://docs.npmjs.com/files/package.json#peerdependencies) to manage the required version of `joi` it will use. This means that if you're using npm@3, *you must* install a compatible version of `joi` (currently *9.x.x*) as a top level dependency for `celebrate` to work correctly. `celebrate` does *not* install its own copy of `joi` when using npm@3. This is to maximize compatibility and to keep the number of `joi` version mismatch bugs to a minimum.

## Usage

Example of using `celebrate` on a single POST route to validate `req.body`.
Expand Down Expand Up @@ -47,9 +48,9 @@ app.use((err, req, res) => {

Example of using `celebrate` to validate all incoming requests to ensure the `token` header is present and mathes the supplied regular expression.
```js
const express = require(express);
const Joi = require(joi);
const Celebrate = require(celebrate);
const express = require('express');
const Joi = require('joi');
const Celebrate = require('celebrate');
const app = express();

// valide all incoming request headers for the token header
Expand Down Expand Up @@ -90,4 +91,4 @@ If any of the configured validation rules fail, the entire request will be consi

## Issues

*Before* opening issues on this repo, make sure your joi schema is correct and workingas you intend. The bulk of this code is just exposing the joi API as Express middleware. All of the heavy lifting still happens inside joi.
*Before* opening issues on this repo, make sure your joi schema is correct and working as you intended. The bulk of this code is just exposing the joi API as Express middleware. All of the heavy lifting still happens inside joi.

0 comments on commit a2eeeb1

Please sign in to comment.