Bounties API allows applications (including the Bounty Bot, Bankless Mobile App, and Bounty Board) to perform Create, Retrieve, Update and Delete operations on bounties.

Progress


API Task List

Technical Spec


Validations

Schema validations are defined in two places:

Yup for API Validation

https://github.com/jquense/yup

Yup is an excellent library for handling schema validation across both DOM and NodeJS environments (read: Frontend and Backend).

Here is an excellent video of getting started with NextJS and Yup:

Next.js API Routes Validation using YUP: Share frontend and backend validation using YUP schemas

We use yup for any validation of objects, before attempting to load to the DB. The advantage here is that any runtime transformations can be independent of the DB Schema.

Yup schema, while a little verbose, can be directly converted to typescript interfaces, so the net gain in code maintenance is worthwhile.

The yup validator is implemented as a middleware in the Next API route. The middleware itself takes 2 arguments:

const validate = ({ schema, handler }: ValidatorProps): ValidatorFunction

Where the schema is the yup schema, and the handler is the next API route handler.