- โจ Zero coding required - Start with a JSON file - ๐ Quick setup - Get an API running in < 30 seconds - ๐ Full REST API - Complete CRUD operations (GET, POST, PUT, PATCH, DELETE) - ๐ Advanced filtering - Filter by any property, use operators like \_gte, \_lte, \_like - ๐ Sorting & Pagination - Sort by multiple fields, paginate with \_page and \_limit - ๐ Relationships - Embed child resources and expand parent resources - ๐ Static file serving - Serve your HTML, CSS, and JS files - ๐จ URL rewriting - Create custom routes and aliases - ๐ง Highly customizable - CLI options and config file support - ๐พ Auto-save - Changes are automatically saved to your data file - ๐ CORS enabled - Ready for cross-origin requests - โก Fast & lightweight - Built with Express and TypeScript - ๐งช Well tested - 214 tests with comprehensive coverage
Or with watch mode to auto-reload on file changes:
`bash rest_api_faker --watch db.json `
Note: Watch mode monitors your data file, routes file, and middlewares file for changes and automatically reloads them.
3. Access your API:
`bash
Get all posts
curl http://localhost:3000/posts
Get a single post
curl http://localhost:3000/posts/1
Get profile
curl http://localhost:3000/profile `
That's it! ๐ You now have a fully functional REST API.
Usage
$3
`bash rest_api_faker [options]
Options: -c, --config Path to config file (default: "rest_api_faker.json") -p, --port Set port (default: 3000) -H, --host Set host (default: "localhost") -w, --watch Watch data, routes, and middlewares files for changes -r, --routes Path to routes file (URL rewrite rules) -m, --middlewares Path to middleware file -s, --static Set static files directory (default: "./public") --no-static Disable static file serving --ro, --read-only Allow only GET requests --nc, --no-cors Disable Cross-Origin Resource Sharing --ng, --no-gzip Disable GZIP Content-Encoding -S, --snapshots Set snapshots directory (default: ".") -d, --delay Add delay to responses (ms) -i, --id Set database id property (default: "id") --fks Set foreign key suffix (default: "Id") -q, --quiet Suppress log messages -l, --log-level Set log level: trace | debug | info (default: "info") -h, --help Show help -v, --version Show version number
Log Levels: trace Show all logs including trace messages (most verbose) debug Show debug and info logs (hide trace) info Show only info logs (default, least verbose)
Examples: rest_api_faker db.json Start with db.json rest_api_faker --watch db.json Start with auto-reload rest_api_faker --port 4000 db.json Start on port 4000 rest_api_faker file.js Use a JavaScript file rest_api_faker --routes routes.json Use custom routes rest_api_faker --log-level debug db.json Show debug logs rest_api_faker --log-level trace db.json Show all logs including trace
`
$3
Based on your
db.json, API Faker automatically creates the following routes:
#### Plural Resources
` GET /posts # List all posts GET /posts/1 # Get post with id=1 POST /posts # Create a new post PUT /posts/1 # Replace post with id=1 PATCH /posts/1 # Update post with id=1 DELETE /posts/1 # Delete post with id=1 `
#### Singular Resources
` GET /profile # Get profile POST /profile # Create/replace profile PUT /profile # Replace profile PATCH /profile # Update profile `
#### Special Routes
` GET /db # Get the full database GET / # Homepage (serves index.html or shows available routes) `
$3
#### Filtering
Filter by any property:
`bash
Posts with specific title
GET /posts?title=Hello World
Multiple values (OR)
GET /posts?id=1&id=2
Deep property access
GET /posts?author.name=John `
#### Pagination
`bash
Get page 2 with 10 items per page
GET /posts?_page=2&_limit=10
Default limit is 10
GET /posts?_page=1 `
Returns
Link header with first, prev, next, and last links.
#### Sorting
`bash
Sort by title (ascending)
GET /posts?_sort=title
Sort by title (descending)
GET /posts?_sort=title&_order=desc
Sort by multiple fields
GET /posts?_sort=author,title&_order=desc,asc `
#### Slicing
`bash
Get items 20-30
GET /posts?_start=20&_end=30
Get 10 items starting from 20
GET /posts?_start=20&_limit=10 `
Returns
X-Total-Count header with the total number of items.
#### Operators
`bash
Greater than or equal
GET /posts?views_gte=1000
Less than or equal
GET /posts?views_lte=100
Not equal
GET /posts?author_ne=John
Like (supports RegExp)
GET /posts?title_like=server `
#### Full-Text Search
`bash
Search across all string fields
GET /posts?q=awesome `
$3
#### Embed Children
Use
_embed to include child resources (based on foreign keys):`bash