Gathering detailed insights and metrics for maggie-api
Gathering detailed insights and metrics for maggie-api
Gathering detailed insights and metrics for maggie-api
Gathering detailed insights and metrics for maggie-api
sprucecss-maggie-marquardt
A template repository to kickstart your Node.js projects with a clean and organized structure. This repository serves as a starting point for your new projects, helping you focus on building great applications right from the beginning.
firan-logging-maggie-lakin
A template repository to kickstart your Node.js projects with a clean and organized structure. This repository serves as a starting point for your new projects, helping you focus on building great applications right from the beginning.
argparse-maggie-hayes
A template repository to kickstart your Node.js projects with a clean and organized structure. This repository serves as a starting point for your new projects, helping you focus on building great applications right from the beginning.
npm install maggie-api
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
29 Commits
1 Branches
1 Contributors
Updated on Jul 06, 2025
Latest Version
1.1.3
Package Id
maggie-api@1.1.3
Unpacked Size
57.81 kB
Size
14.59 kB
File Count
26
NPM Version
10.2.3
Node Version
20.10.0
Published on
Jul 06, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
Auto-generate full-featured CRUD APIs for your Mongoose models in Express with one powerful config.
Supports:
$gte
, $in
)1npm install maggie-api 2 3# Peer dependencies 4npm install express mongoose joi
1import express from "express"; 2import { createMaggie } from "maggie-api"; 3import Models from "./models"; 4import Joi from "joi"; 5 6const app = express(); 7app.use(express.json()); 8 9const UserValidationSchema = Joi.object({ 10 _id: Joi.string(), 11 firstName: Joi.string().required(), 12 lastName: Joi.string().required(), 13 email: Joi.string().email().required(), 14}); 15 16const apiRouter = createMaggie({ 17 prefix: "/api/v1", 18 models: [ 19 { 20 model: ProductModel, 21 path: "product", 22 validationSchema: productValidationSchema, 23 settings: { 24 get: { 25 // ✅ Only these fields will be returned in GET /product 26 keys: ["_id", "title", "price", "description", "subCategory"], 27 28 // 🔍 Search by title or description using `?search=some+word` 29 search: { 30 disabled: false, 31 allowedFields: ["title", "description"], 32 }, 33 34 // 🧹 Allow filtering via `?filter[price][gte]=100` or `filter[title]=Shoes` 35 filter: { 36 allowedFields: ["price", "title", "subCategory"], 37 }, 38 39 // 🔗 Populate referenced subCategory and its category 40 populate: [ 41 { 42 path: "subCategory", 43 select: ["_id", "title"], 44 populate: [{ path: "category", select: ["_id", "title"] }], 45 }, 46 ], 47 }, 48 49 getById: { 50 // ✅ Only these fields will be returned in GET /product/:id 51 keys: ["_id", "title", "description", "price", "subCategory"], 52 53 // 🔗 Nested populate same as `get` 54 populate: [ 55 { 56 path: "subCategory", 57 select: ["_id", "title"], 58 populate: [{ path: "category", select: ["_id", "title"] }], 59 }, 60 ], 61 }, 62 }, 63 }, 64 ], 65}); 66 67app.use(apiRouter); 68 69app.listen(3000, () => { 70 console.log("Server running at http://localhost:3000"); 71});
POST /:model
)_id
, it triggers an update; otherwise, a new record is created.primaryKey
uniqueness during creation.POST
operations.primaryKey
(e.g. email
, username
) to enforce uniqueness on creation.middleWares
array to inject custom Express middlewares into the POST
route.getKeys
and getByIdKeys
are deprecated.settings.get.keys
to select fields in GET /:model
.settings.getById.keys
to select fields in GET /:model/:id
.Method | Endpoint | Description |
---|---|---|
POST | /api/v1/user | Create or Update User |
POST | /api/v1/user/bulk | Bulk Insert Users |
GET | /api/v1/user | Fetch all Users |
GET | /api/v1/user/:id | Fetch User by ID |
DELETE | /api/v1/user/:id | Delete User by ID |
settings.get.populate
and settings.getById.populate
to populate referenced fields.path
and optional select
array for nested or targeted population.1settings: { 2 get: { 3 populate: [ 4 { path: "department", select: ["_id", "title"] } 5 ] 6 }, 7 getById: { 8 populate: [ 9 { 10 path: "department", 11 select: ["_id", "title"] , 12 populate: [ 13 { 14 path: "item", 15 selected: ["_id", "title"] 16 } 17 ], 18 } 19 ] 20 } 21}
settings.get.search
to enable keyword-based searching on specific fields.search
, searchFields
, and caseSensitive
.allowedFields
will be considered for searching.disabled: true
, searching will be turned off for that model.searchFields
param is not provided.Example Setting:
1settings: { 2 get: { 3 search: { 4 disabled: false, 5 allowedFields: ["title", "description", "email"] 6 } 7 } 8}
Sample Request:
1GET /api/v1/user?search=mascara&searchFields=title,description&caseSensitive=false
Behavior:
$or
regex search query for all specified fields.Sorting, pagination, and filtering are first-class citizens in maggie-api
, available out of the box for all models.
Pass a sort
query param to define sort order:
1?sort=-createdAt,name
Use a hyphen (-
) prefix for descending order.
Multiple fields can be sorted in sequence.
Sorting is always enabled — no extra config needed.
Supports standard pagination via limit
and page
query parameters:
1?limit=10&page=2
Only applied when both parameters are valid positive integers.
Automatically returns metadata:
1{ 2 "users": [...], 3 "pagination": { 4 "total": 100, 5 "page": 2, 6 "limit": 10, 7 "totalPages": 10 8 } 9}
If not provided, returns the full result set without pagination.
1GET /api/v1/product?filter[price][gte]=500&sort=-createdAt&limit=10&page=1
⚠️ Sorting and pagination are always enabled by default. Filtering requires configuring
allowedFields
to avoid accidental or insecure filtering.
This makes it easy to power powerful, customizable tables and dashboards with minimal backend configuration.
maggie-api
allows powerful and flexible filtering on API endpoints using structured query parameters.
settings.get.filter.allowedFields
Operator | Usage | Translates To |
---|---|---|
eq | filter[status]=active | { status: "active" } |
in | filter[tags][]=a&[]=b | { tags: { $in: [...] } } |
gte | filter[price][gte]=100 | { price: { $gte: 100 } } |
lte | filter[price][lte]=500 | { price: { $lte: 500 } } |
gt, lt | Similar usage | $gt , $lt |
allowedFields
, it will be silently ignored.1GET /api/v1/user?filter[role]=admin&filter[age][gte]=18
search
config insteadThis filtering system is perfect for admin dashboards, search filters, and dynamic list views.
1curl -X POST http://localhost:3000/api/v1/user \ 2-H "Content-Type: application/json" \ 3-d '{"firstName":"Alice","lastName":"Doe","email":"alice@example.com"}'
1curl -X POST http://localhost:3000/api/v1/user \ 2-H "Content-Type: application/json" \ 3-d '{"_id":"665c8d1234567890","firstName":"Alicia","email":"alice@example.com"}'
1curl http://localhost:3000/api/v1/user
1curl http://localhost:3000/api/v1/user/665c8d1234567890
1curl -X DELETE http://localhost:3000/api/v1/user/665c8d1234567890
1curl -X POST http://localhost:3000/api/v1/user/bulk \ 2-H "Content-Type: application/json" \ 3-d '[ 4 {"firstName":"Bob","lastName":"Smith","email":"bob@example.com"}, 5 {"firstName":"Carol","lastName":"Jones","email":"carol@example.com"} 6]'
maggie-api
follows a consistent, frontend-friendly response structure for all CRUD operations.
Create:
1{ 2 "success": true, 3 "statusCode": 201, 4 "message": "User created successfully", 5 "data": { 6 "_id": "665c8d1234567890", 7 "firstName": "Alice", 8 "email": "alice@example.com" 9 } 10}
Update:
1{ 2 "success": true, 3 "statusCode": 200, 4 "message": "User updated successfully", 5 "data": { 6 "_id": "665c8d1234567890", 7 "firstName": "Alicia" 8 } 9}
Get All (with optional pagination):
1{ 2 "success": true, 3 "statusCode": 200, 4 "message": "Users fetched successfully", 5 "data": { 6 "users": [...], 7 "pagination": { 8 "total": 100, 9 "page": 2, 10 "limit": 10, 11 "totalPages": 10 12 } 13 } 14}
Get by ID:
1{ 2 "success": true, 3 "statusCode": 200, 4 "message": "User fetched successfully", 5 "data": { 6 "_id": "665c8d1234567890", 7 "firstName": "Alice" 8 } 9}
Delete:
1{ 2 "success": true, 3 "statusCode": 200, 4 "message": "User deleted successfully", 5 "data": { 6 "_id": "665c8d1234567890" 7 } 8}
Bulk Insert:
1{ 2 "success": true, 3 "statusCode": 201, 4 "message": "3 Users created successfully", 5 "data": [{}, {}, {}] 6}
Validation Error:
1{ 2 "success": false, 3 "statusCode": 400, 4 "message": "Validation error", 5 "error": "\"email\" is required" 6}
Duplicate Primary Key (Create or Bulk Insert):
1{ 2 "success": false, 3 "statusCode": 409, 4 "message": "User with this email already exists", 5 "data": null 6}
Document Not Found (Update or GetById):
1{ 2 "success": false, 3 "statusCode": 404, 4 "message": "User not found", 5 "data": null 6}
Invalid Request Format (e.g. Bulk Insert with non-array):
1{ 2 "success": false, 3 "statusCode": 400, 4 "message": "Request body must be a non-empty array of documents", 5 "data": null 6}
Server Error:
1{ 2 "success": false, 3 "statusCode": 500, 4 "message": "Failed to process User", 5 "data": null 6}
your-app/
├── models/
│ └── User.ts
├── routes/
│ └── index.ts
├── utils/
│ └── validateBody.ts
├── app.ts
└── ...
Want to contribute or enhance? PRs are welcome!
Save hours of boilerplate setup. Focus on your app logic.
Let maggie-api
handle the API plumbing. 🚀
No vulnerabilities found.
No security vulnerabilities found.