fexapi
v0.3.4
Published
Mock API generation CLI tool for local development and testing
Maintainers
Readme
FexAPI
Frontend Experience API - Mock API generation CLI tool for local development and testing.
Installation
npm install -g fexapiUsage
fexapi [options]Prisma-like Flow (Dynamic)
1) Initialize
npx fexapi@latest initor
pnpm dlx fexapi@latest initor
yarn dlx fexapi@latest initor
bunx fexapi@latest initfexapi init runs an interactive setup wizard and asks:
- What port? (default: 4000)
- Enable CORS? (Y/n)
Creates:
fexapi/schema.fexapifexapi.config.js
Tip: if you see old prompts (for example default 3000 or "Generate sample schemas"), run with @latest as shown above to ensure every package manager resolves the same release.
2) Edit schema file
fexapi/schema.fexapi supports readable multi-line route fields (single-line still works):
# Server
port: 4100
# Routes
GET /users:
id:uuid
name:name
email:email
age:number
phone:phone
pic:url
courseName:string
GET /courses:
id:uuid
courseName:string
mentor:name
# one-line format is also valid:
# GET /users: id:uuid,name:name,email:email3) Generate artifacts (updates migration)
npx fexapi generateGenerates:
fexapi/generated.api.jsonfexapi/migrations/schema.json
3a) Format schema (optional)
Auto-format your schema to use readable multi-line field formatting:
npx fexapi formatThis rewrites fexapi/schema.fexapi with each field on its own indented line for better readability.
4) Start server
npx fexapi run
# or
npx fexapi serve
# request/response logging
npx fexapi serve --log
# or dev watch mode (nodemon-like)
npx fexapi dev --watch
# watch mode + request logs
npx fexapi dev --watch --log
# or (inside local workspace package)
npm run serveServer port is read from schema.fexapi unless overridden by CLI --port.
fexapi dev --watch auto-reloads when these files change:
fexapi/schema.fexapifexapi/generated.api.jsonfexapi.config.jsfexapi.config.jsonschemas/*.yaml
fexapi serve --log prints request logs like:
[GET] /users/1 → 200 (45ms)[POST] /posts → 201 (12ms)
Configuration File Support
Create a fexapi.config.js in your project root:
// fexapi.config.js
module.exports = {
port: 3000,
routes: {
"/users": { count: 50, schema: "user" },
"/posts": { count: 100, schema: "post" },
},
cors: true,
delay: 200,
};Then run:
fexapi serveNotes:
portsets the default server port (CLI--portstill has priority).routesmaps endpoint paths to generated payload settings.schemamaps to files underfexapi/schemas/(for exampleschema: "user"->fexapi/schemas/user.yaml); unknown names fall back to a generic record.cors: trueenables CORS headers and OPTIONS preflight handling.delayadds response latency in milliseconds.
Custom Schema Definitions
You can define custom schemas in YAML files under fexapi/schemas/.
# fexapi/schemas/user.yaml
name:
type: string
faker: person.fullName
email:
type: string
faker: internet.email
age:
type: number
min: 18
max: 80Then reference it in fexapi.config.js:
routes: {
"/users": { count: 50, schema: "user" }
}Notes:
- Supported file extensions:
.yaml,.yml - Schema name is taken from filename (for example
fexapi/schemas/user.yaml->schema: "user") fakervalues map to Faker paths likeperson.fullName,internet.email
Features
- Schema-based mock API generation
- Local development server
- Faker.js integration
- Easy setup for testing workflows
License
MIT
