How to use the koa-joi-router.Joi.string function in koa-joi-router

To help you get started, we’ve selected a few koa-joi-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github a-s-o / koa-docs / example / routes / pets.js View on Github external
}
};


const getPetByStatus = {
   method: 'put',
   path: '/pet',
   meta: {
      friendlyName: 'Find pets by status'
   },
   validate: {
      type: 'json',
      query: {
         status: t.array()
            .description('Status values that need to be considered for filter')
            .items(t.string())
            .min(1)        // At least 1 should be provided
            .single()      // If only one is provided, wrap it in an array
      },
      output: {
        200: {
          body: t.array().items(Pet.requiredKeys('id', 'status')),
          header: {
            'Content-Type': t.string()
          }
        }
      }
   },
   *handler () {
      const query = this.request.query;

      return yield this.db()
github a-s-o / koa-docs / example / routes / store.js View on Github external
body: {
            code: t.number().integer().min(0).max(100).default(0).description('Code to explain the response.'),
            errors: t.object().keys({
              name: {
                message: t.string().required().default('Some pet has no name!').description('Thrown when some pets has no name.')
              }
            }),
            tags: t.array().items(t.object().keys({
              label: t.string().example('Hello').example('World'),
              signal: t.array().items(t.string())
            })),
            error: t.string().valid('Pets not found!').description('Pets not found!')
          }
        },
        500: {
          body: t.string().default('Server Internal Error.')
        }
      }
   },
   *handler () {
      // This route does not have any validations
      return this.db().table('store')
         .groupBy('statusCode')
         .map('quantity')
         .run();
   }
};

const orderPet = {
   method: 'post',
   path: '/order',
   meta: {
github interledgerjs / rafiki / packages / rafiki-admin-api / src / index.ts View on Github external
try {
          const account = await accounts.get(ctx.request.params.id)
          ctx.body = account
        } catch (error) {
          ctx.response.status = 404
        }
      }
    })
    middlewareRouter.route({
      method: 'post',
      path: '/peers',
      validate: {
        body: {
          id: Joi.string().required(),
          relation: Joi.string().required(),
          url: Joi.string().optional()
        },
        type: 'json'
      },
      handler: async (ctx: Context) => {
        const peerInfo = ctx.request.body
        const peer = await peers.add(peerInfo)
        // const account = await accounts.set()
        // TODO: Do we create the token automatically
        // await tokenService.create({ sub: peerInfo.id, active: true })
        ctx.response.body = peer
        ctx.response.status = 201
      }
    })
    middlewareRouter.route({
      method: 'get',
      path: '/peers',
github a-s-o / koa-docs / example / routes / store.js View on Github external
body: {
            available: Quantity.description('Pets available for sale'),
            pending: Quantity.description('# of pets awaiting processing'),
            sold: Quantity.description('# of pets sold')
          }
        },
        400: {
          body: {
            code: t.number().integer().min(0).max(100).default(0).description('Code to explain the response.'),
            errors: t.object().keys({
              name: {
                message: t.string().required().default('Some pet has no name!').description('Thrown when some pets has no name.')
              }
            }),
            tags: t.array().items(t.object().keys({
              label: t.string().example('Hello').example('World'),
              signal: t.array().items(t.string())
            })),
            error: t.string().valid('Pets not found!').description('Pets not found!')
          }
        },
        500: {
          body: t.string().default('Server Internal Error.')
        }
      }
   },
   *handler () {
      // This route does not have any validations
      return this.db().table('store')
         .groupBy('statusCode')
         .map('quantity')
         .run();
github a-s-o / koa-docs / example / routes / store.js View on Github external
sold: Quantity.description('# of pets sold')
          }
        },
        400: {
          body: {
            code: t.number().integer().min(0).max(100).default(0).description('Code to explain the response.'),
            errors: t.object().keys({
              name: {
                message: t.string().required().default('Some pet has no name!').description('Thrown when some pets has no name.')
              }
            }),
            tags: t.array().items(t.object().keys({
              label: t.string().example('Hello').example('World'),
              signal: t.array().items(t.string())
            })),
            error: t.string().valid('Pets not found!').description('Pets not found!')
          }
        },
        500: {
          body: t.string().default('Server Internal Error.')
        }
      }
   },
   *handler () {
      // This route does not have any validations
      return this.db().table('store')
         .groupBy('statusCode')
         .map('quantity')
         .run();
   }
};
github a-s-o / koa-docs / example / routes / pets.js View on Github external
friendlyName: 'Find pets by status'
   },
   validate: {
      type: 'json',
      query: {
         status: t.array()
            .description('Status values that need to be considered for filter')
            .items(t.string())
            .min(1)        // At least 1 should be provided
            .single()      // If only one is provided, wrap it in an array
      },
      output: {
        200: {
          body: t.array().items(Pet.requiredKeys('id', 'status')),
          header: {
            'Content-Type': t.string()
          }
        }
      }
   },
   *handler () {
      const query = this.request.query;

      return yield this.db()
         .table('pets')
         .getAll(query.status)
         .run();
   }
};

module.exports = [
   createPet,
github a-s-o / koa-docs / example / routes / pets.js View on Github external
const t = require('koa-joi-router').Joi;

const Category = t.object().label('Category').keys({
   id: t.number(),
   name: t.string()
});

const Tag = t.object().label('Tag').keys({
   id: t.number(),
   name: t.string()
});

const Pet = t.object().label('Pet').keys({
   id: t.number().optional(),
   name: t.string().required(),
   category: Category,
   tags: t.array().items(Tag),
   photoUrls: t.array().items(t.string()).required(),
   status: t.string()
      .valid(['available', 'pending', 'sold'])
      .description('pet status in the store')
});

const createPet = {
   method: 'post',
   path: '/pet',
   meta: {
      friendlyName: 'Add pet',
      description: 'Add a new pet to the store'
   },
   validate: {
github npms-io / npms-api / lib / controllers / search.js View on Github external
const builder = (router, container) => {
    router.route({
        method: 'get',
        path: '/search',
        validate: {
            query: {
                term: Joi.string().min(1).max(255).required(),
                from: Joi.number().min(0),
                size: Joi.number().min(0),
                effect: Joi.number().min(0),
                weightQuality: Joi.number().min(0),
                weightPopularity: Joi.number().min(0),
                weightMaintenance: Joi.number().min(0),
            },
        },
        handler: handler(container.elasticClient),
    });

    return router;
};
github interledgerjs / rafiki / packages / rafiki-accounting-system / src / routes.ts View on Github external
},
      body: {
        amount: Joi.string().required(),
        scale: Joi.number().required()
      },
      type: 'json'
    },
    handler: createSettlement
  })

  router.route({
    method: 'post',
    path: '/accounts/:id/messages',
    validate: {
      params: {
        id: Joi.string().required()
      }
    },
    handler: createMessage
  })

  return router
}

koa-joi-router

Configurable, input validated routing for koa.

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis