All Projects → stearm → micro-joi

stearm / micro-joi

Licence: MIT license
A Joi wrapper for zeit/micro

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to micro-joi

felicity
Javascript object constructors and sample data based on Joi schema.
Stars: ✭ 107 (+132.61%)
Mutual labels:  schema, joi
koa-restful-boilerplate
A boilerplate for koa2 RESTful API development
Stars: ✭ 31 (-32.61%)
Mutual labels:  joi
hooked
Microservice for communicating between Contentful and Shopify
Stars: ✭ 17 (-63.04%)
Mutual labels:  micro
granate
Code generator for graphql
Stars: ✭ 21 (-54.35%)
Mutual labels:  schema
really-rich-results
RRR makes structured data for WordPress really rich, and really easy.
Stars: ✭ 21 (-54.35%)
Mutual labels:  schema
rest-api-node-typescript
This is a simple REST API with node and express with typescript
Stars: ✭ 154 (+234.78%)
Mutual labels:  joi
micro-airtable-api
Quickly make an API from Airtable
Stars: ✭ 30 (-34.78%)
Mutual labels:  micro
schema-registry
📙 json & avro http schema registry backed by Kafka
Stars: ✭ 23 (-50%)
Mutual labels:  schema
doc-us
A MySQL Schema Documentation Generator for Laravel.
Stars: ✭ 33 (-28.26%)
Mutual labels:  schema
NoSE
👃 Automated schema design for NoSQL applications
Stars: ✭ 25 (-45.65%)
Mutual labels:  schema
microauth
Collection of authentication modules for ▲zeit's micro.
Stars: ✭ 71 (+54.35%)
Mutual labels:  micro
pocket-cms
☁️ A pocket sized CMS written for nodejs
Stars: ✭ 13 (-71.74%)
Mutual labels:  schema
ethereumjs-account
Project is in active development and has been moved to the EthereumJS VM monorepo.
Stars: ✭ 45 (-2.17%)
Mutual labels:  schema
JetBrains-scheme
JetBrains主题,更完美的高亮。支持 IntelliJ IDEA、phpstorm、goland、webstorm
Stars: ✭ 25 (-45.65%)
Mutual labels:  schema
micro-plugins
go-micro plugins, auth(JWT+Casbin)、go-micro服务加入istio服务网格
Stars: ✭ 27 (-41.3%)
Mutual labels:  micro
Micro
Micro is coming back!
Stars: ✭ 11 (-76.09%)
Mutual labels:  micro
faker-schema
Generate fake data using joke2k's faker and your own schema
Stars: ✭ 91 (+97.83%)
Mutual labels:  schema
avro turf
A library that makes it easier to use the Avro serialization format from Ruby.
Stars: ✭ 130 (+182.61%)
Mutual labels:  schema
phalcon-micro-rest-api-skeleton
This is a basic API REST skeleton written on Phalcon PHP. Great For building an MVP for your frontend app (Vue, react, angular, or anything that can consume an API)
Stars: ✭ 57 (+23.91%)
Mutual labels:  micro
openapi
GitHub's official OpenAPI spec with Octokit extensions
Stars: ✭ 24 (-47.83%)
Mutual labels:  schema

⚠️ Deprecated ⚠️

Build Status npm

micro-joi

A Joi wrapper for Micro to validate your request body and query parameters.

It's possible to validate both body and query parameters, or only one of these. To validate both, use body and query key in the schema:

Joi.object({
    body: Joi.object({
        ...
    }),
    query: Joi.object({
        ...
    })
});

To keep api backward compatible, you can write the shape of your request body directly, look at the examples below.

Examples

const { json, send } = require('micro')
const validation = require('micro-joi')
const Joi = require('@hapi/joi')

const validator = validation(Joi.object({
    foo: Joi.number().required(),
    bar: Joi.number().required()
}))

async function handler (req, res) {
  const body = await json(req)
  send(res, 200, body)
}

module.exports = validator(handler)

Sending a POST with a wrong body, e.g. { foo: 42, bar: "fortytwo" }, will return an error with a Joi validation message, status code 400.

or with custom message

const { json, send } = require('micro')
const validation = require('micro-joi')
const Joi = require('@hapi/joi')

const validator = validation(Joi.object({
    foo: Joi.number().required(),
    bar: Joi.number().required()
}), 'hei! send a correct body plz')

async function handler (req, res) {
  const body = await json(req)
  send(res, 200, body)
}

It will return an error with your custom message, status code 400.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].