GithubHelp home page GithubHelp logo

api-joi-validator-practice's Introduction

APIs

{get} /lesson/v1
{get} /lesson/v2
{get} /lesson/v3

{get} /lesson/v1/channel
{get} /lesson/v2/channel
{get} /lesson/v3/channel

예시1

{get} /lesson/v1/channel

{
    "message": "channelIndex is required, query must contain at least one of [index, sequence]",
    "code": "ValidationError",
    "asdf": "this is error handler in app"
}

{get} /lesson/v2/channel

{
    "message": [
        "channelIndex is required",
        "query must contain at least one of [index, sequence]"
    ],
    "code": "ValidationError",
    "asdf": "this is error handler in app"
}

{get} /lesson/v3/channel

{
    "message": "channelIndex is required, query must contain at least one of [index, sequence]",
    "code": "ValidationError",
    "asdf": "this is error handler in api"
}

차이

v1 VS v2

  • 에러 메세지 포맷 차이

v1 VS v3

  • 에러 핸들 방식 차이

예시2

router.post("/v1", validate(postLesson, { convert: false }), (req, res) => {
    return res.json(req.body);
});

router.post("/v2", validate(postLesson), (req, res) => {
    return res.json(req.body);
});

// ------- postLesson
exports.postLesson = {
    body: commonJoi.keys({
        subject: Joi.string().required(),
        count: Joi.number(),
    }),
};
// body
{
    "subject": "aaa",
    "index": "123123",
    "count": "123"  // v1 - 에러 발생, v2 - 에러 X
}

api-joi-validator-practice's People

Contributors

devookim avatar sammykimgoorm avatar

Watchers

 avatar

Forkers

sammykimgoorm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.