codegen
generate your api routes for development and production. Use mocks to build api routes for local envs. Works perfect for next.js and deno. Built for vercel to easily build lambdas that work in any environment.
Getting Started
Make sure to create a mocks and a schemas directory. Check out the schema section to learn how to build your api. The idea is that the api routes are always checked in .gitignore and built at the build level for systems. Its better to setup the module to be used via script to run with pre-install scripts or pre-build scripts - checkout build.sh for an example.
import { codegen } from "https://deno.land/x/codegen/mod.ts";
codegen();Configuration
example: schema
{
"endpoints": [
{
"path": "/login",
"url": "auth/api/token",
"method": "POST",
"mock": {
"data": {
"access_token": "Bearer @Something",
"refresh_token": ""
},
"data:error": {
"message": "Authentication error, please check your email or password and try again."
},
"validator": {
"fields": [
{ "name": "password", "message": "Password is required." },
{ "name": "username", "message": "User name is required." }
]
}
}
}
]
}Mocks
In order to import a mock file add @import filename under the mock.data key and replace filename with the mock path in the mocks folder. Make sure to export your mock correctly.
{
"endpoints": [
{
"path": "/friends",
"url": "friends/api/list",
"method": "GET",
"mock": {
"data": "@import friends",
"data:error": {
"message": "Access denied."
}
}
}
]
}Make sure to export the var named as mock in order for the builder to pick it up.
export const mock = ["hi", "bye"];Schema
A json file named of the lambda functions that you are going to create.
TODO: checkout initial schema example.