All Projects → brandon93s → micro-superstruct

brandon93s / micro-superstruct

Licence: MIT license
A Superstruct wrapper for Micro to validate your request body and query parameters

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to micro-superstruct

Microenvi
Bundle, serve, and hot reload with one command
Stars: ✭ 120 (+700%)
Mutual labels:  micro
Stack Rpc Tutorials
Stack-RPC 中文示例、教程、资料,源码解读
Stars: ✭ 1,736 (+11473.33%)
Mutual labels:  micro
Go Os
Stars: ✭ 185 (+1133.33%)
Mutual labels:  micro
Go Plugins
Go Micro Plugins. Moved to go-micro/plugins.
Stars: ✭ 1,654 (+10926.67%)
Mutual labels:  micro
Micro Medium Api
Microservice for fetching the latest posts of Medium with GraphQL.
Stars: ✭ 138 (+820%)
Mutual labels:  micro
Micro Starter Kit
Cloud Native GoLang Microservices - gRPC, GraphQL
Stars: ✭ 167 (+1013.33%)
Mutual labels:  micro
Mconf
微服务配置中心 mconf ,基于 Zookeeper和Redis实现的配置中心。提供拉取配置、订阅配置、新增配置、删除配置、修改配置等功能。支持多数据中心、多环境配置、配置分组、多版本配置等功能。
Stars: ✭ 112 (+646.67%)
Mutual labels:  micro
Reshader
A micro, highly-customisable JavaScript library to get shades of colors
Stars: ✭ 214 (+1326.67%)
Mutual labels:  micro
Micro Starter
[Deprecated] 🔷 Basic (opinionated) starter kit for a micro app with webpack build
Stars: ✭ 144 (+860%)
Mutual labels:  micro
Xconf
分布式配置中心
Stars: ✭ 185 (+1133.33%)
Mutual labels:  micro
Nano
Lightweight, facility, high performance golang based game server framework
Stars: ✭ 1,888 (+12486.67%)
Mutual labels:  micro
Go Grpc
A simpler grpc framework
Stars: ✭ 133 (+786.67%)
Mutual labels:  micro
Micro Cluster
Run multiple micro servers and a front proxy at a time
Stars: ✭ 173 (+1053.33%)
Mutual labels:  micro
Micro Jaymock
Tiny API mocking microservice for generating fake JSON data.
Stars: ✭ 123 (+720%)
Mutual labels:  micro
Unfurl
Scraper for oEmbed, Twitter Cards and Open Graph metadata - fast and Promise-based ⚡️
Stars: ✭ 193 (+1186.67%)
Mutual labels:  micro
Node Frameworks Benchmark
Simple HTTP benchmark for different nodejs frameworks using wrk
Stars: ✭ 117 (+680%)
Mutual labels:  micro
Microjs.com
Fantastic Micro-Frameworks and Micro-Libraries for Fun and Profit!
Stars: ✭ 1,927 (+12746.67%)
Mutual labels:  micro
prismy
🌈 Simple and fast type safe server library for now.sh v2 and API routes of next.js.
Stars: ✭ 46 (+206.67%)
Mutual labels:  micro
Qian
A minimalist file-explorer using Electron via Elm !
Stars: ✭ 198 (+1220%)
Mutual labels:  micro
Wehousing
Golang微服务+区块链实战---go+micro+fabric实现租房上链系统
Stars: ✭ 182 (+1113.33%)
Mutual labels:  micro

micro-superstruct Build Status

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

Install

npm install micro-superstruct

Usage

micro-superstruct exports a validate function that allows you to create API validators from any Struct:

const {object, string, number} = require('superstruct')
const {json, send} = require('micro')
const validate = require('micro-superstruct')

// define a Superstruct `Struct`
const Unicorn = object({
  name: string(),
  age: number(),
  color: string()
})

// create a validator
const validator = validate(Unicorn)

// write your Micro API
const handler = async (req, res) => {
  const body = await json(req)
  send(res, 200, body)
}

// export validated service
module.exports = validator(handler)

Requests that fail validation will return a 400 error along with a Superstruct validation message:

Error

API

validate(config)

Returns a validator function that can be used to validate a Micro handler.

config

Type: Struct | object

Passing a Struct directly will configure request body validation using the provided validator.

Passing an object allows for validation of both the request body and query string. Both are optional.

// body validation
validate(object({}))

// body and/or query validation
validate({
  body: object({}),
  query: object({})
})

Request Properties

micro-superstruct attaches validated body and/or query objects to the request object for use by the API handler:

const validator = validate(Unicorn)

const handler = async (req, res) => {
  const {body, query} = req
  send(res, 200, body)
}

License

MIT © Brandon Smith

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].