{"id":13716405,"url":"https://github.com/stearm/micro-joi","last_synced_at":"2025-05-07T05:32:57.790Z","repository":{"id":20133549,"uuid":"88901291","full_name":"stearm/micro-joi","owner":"stearm","description":"A Joi wrapper for zeit/micro","archived":true,"fork":false,"pushed_at":"2023-01-03T18:27:59.000Z","size":935,"stargazers_count":46,"open_issues_count":10,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T03:49:00.729Z","etag":null,"topics":["joi","micro","microservice","schema","validation"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stearm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-20T19:07:13.000Z","updated_at":"2023-04-05T14:42:01.000Z","dependencies_parsed_at":"2023-01-13T20:47:53.377Z","dependency_job_id":null,"html_url":"https://github.com/stearm/micro-joi","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stearm%2Fmicro-joi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stearm%2Fmicro-joi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stearm%2Fmicro-joi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stearm%2Fmicro-joi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stearm","download_url":"https://codeload.github.com/stearm/micro-joi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823399,"owners_count":21809704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["joi","micro","microservice","schema","validation"],"created_at":"2024-08-03T00:01:10.187Z","updated_at":"2025-05-07T05:32:57.481Z","avatar_url":"https://github.com/stearm.png","language":"JavaScript","funding_links":[],"categories":["Modules","schema"],"sub_categories":["Wrappers"],"readme":"# ⚠️ Deprecated ⚠️\n\n[![Build Status](https://travis-ci.org/stearm/micro-joi.svg?branch=master)](https://travis-ci.org/stearm/micro-joi) [![npm](https://img.shields.io/npm/v/micro-joi.svg)](https://www.npmjs.com/package/micro-joi)\n# micro-joi\nA [Joi](https://github.com/hapijs/joi) wrapper for [Micro](https://github.com/zeit/micro) to validate your request body and query parameters.\n\nIt's possible to validate both body and query parameters, or only one of these.\nTo validate both, use `body` and `query` key in the schema:\n```javascript\nJoi.object({\n    body: Joi.object({\n        ...\n    }),\n    query: Joi.object({\n        ...\n    })\n});\n```\nTo keep api backward compatible, you can write the shape of your request body directly, look at the examples below.\n\n## Examples\n\n```javascript\nconst { json, send } = require('micro')\nconst validation = require('micro-joi')\nconst Joi = require('@hapi/joi')\n\nconst validator = validation(Joi.object({\n    foo: Joi.number().required(),\n    bar: Joi.number().required()\n}))\n\nasync function handler (req, res) {\n  const body = await json(req)\n  send(res, 200, body)\n}\n\nmodule.exports = validator(handler)\n```\n\nSending a `POST` with a wrong body, e.g. ```{ foo: 42, bar: \"fortytwo\" }```, will return an error with a Joi validation message, status code 400.\n\n#### or with custom message\n\n```javascript\nconst { json, send } = require('micro')\nconst validation = require('micro-joi')\nconst Joi = require('@hapi/joi')\n\nconst validator = validation(Joi.object({\n    foo: Joi.number().required(),\n    bar: Joi.number().required()\n}), 'hei! send a correct body plz')\n\nasync function handler (req, res) {\n  const body = await json(req)\n  send(res, 200, body)\n}\n```\n\nIt will return an error with your custom message, status code 400.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstearm%2Fmicro-joi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstearm%2Fmicro-joi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstearm%2Fmicro-joi/lists"}