Registry / devops / wajez-api

wajez-api

JSON →
library1.6.2jsnpmunverified

Wajez API is a library built on Express and Mongoose to simplify REST API development by generating CRUD routes from Mongoose models and relations. Current stable version is 1.6.2. It follows a functional programming style using Sanctuary, offering full control over routes and actions. Differentiators include automatic route generation based on model relations (one-to-many, many-to-many), built-in pagination, sorting, and filtering. Release cadence is sporadic; last update was in 2019. Suited for rapid prototyping but not actively maintained.

npm install wajez-api
INSTALL
IMPORT
SIG · WAJEZ-API
W
wajez-api
devopsjavascriptv1.6.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

api
✓ import { api } from 'wajez-api'
✗ const api = require('wajez-api')
Library supports both CJS and ESM; named export required.
oneMany
✓ import { oneMany } from 'wajez-api'
✗ const { oneMany } = require('wajez-api').oneMany
Direct named import works; no default export.
manyMany
✓ import { manyMany } from 'wajez-api'
Available for many-to-many relations.

Sets up a REST API for User and Post models with a one-to-many relation, including error handling.

const express = require('express'); const bodyParser = require('body-parser'); const mongoose = require('mongoose'); const { api, oneMany } = require('wajez-api'); // Connect to MongoDB mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/test', { useNewUrlParser: true, useUnifiedTopology: true }); // Define Mongoose models const UserSchema = new mongoose.Schema({ name: String, email: String }); const PostSchema = new mongoose.Schema({ title: String, content: String, author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } }); const User = mongoose.model('User', UserSchema); const Post = mongoose.model('Post', PostSchema); // Define relations const relations = [oneMany('User', 'posts', 'Post', 'author')]; // Create Express app const app = express(); app.use(bodyParser.json()); // Use wajez-api app.use(api([User, Post], relations)); // Error handler app.use((err, req, res, next) => { console.error(err); res.status(500).json({ error: err.message }); }); app.listen(3000, () => console.log('API running on port 3000'));
Debug
Known issues
deprecatedThe API generator no longer receives updates; consider using more modern solutions like NestJS or express-generator.
fix
Evaluate alternative frameworks.
affects: >=1.0.0
gotchaMust use body-parser middleware before api() to parse JSON bodies; otherwise req.body is undefined.
fix
Add app.use(bodyParser.json()) before app.use(api(...)).
affects: >=1.0.0
gotchaMongoose models must be defined with proper ObjectId references for relations to work; otherwise relation routes may fail silently.
fix
Ensure model schemas include 'ref' in ObjectId fields used in relations.
affects: >=1.0.0
breakingv1.2.0 changed default pagination limit from 20 to 100.
fix
Update app to handle larger default limit or set limit explicitly.
affects: <1.2.0
Errors
Common errors & fixes
Cannot find module 'wajez-api'
Package not installed or import path incorrect.
fix
Run 'npm install wajez-api' and ensure no typo in require/import statement.
TypeError: Cannot read property 'find' of undefined
Mongoose model not connected to MongoDB or model is not properly defined.
fix
Verify mongoose.connect() is called and model schema is correct.
Cannot read property 'id' of undefined
Route parameter not parsed correctly; often due to missing body-parser.
fix
Add bodyParser.json() middleware before using wajez-api.
Upgrade
Version history
1.6.2latest on npm
Audit
Dependencies
expressrequiredHTTP server framework
mongooserequiredMongoDB ODM for models
Agent activity
14 hits · last 30 days
node
14
Resources
wajez-api — npm install wajez-api · libregistry