@theutkarshdev/rapid-api-kit
v1.2.0
Published
Zero-config REST API generator with file uploads. Give your MongoDB creds + schema, get full CRUD endpoints with Swagger docs and Vercel Blob file uploads instantly.
Maintainers
Readme
rapid-api-kit 🚀
Zero-config REST API generator. Give your MongoDB creds + schema, get full CRUD endpoints with Swagger docs instantly. Now with file upload support via Vercel Blob Storage!
Built for frontend students who need quick backend APIs to practice with — no backend knowledge needed!
What You Get
For each resource you define, you automatically get:
| Method | Endpoint | Description |
| -------- | --------------------- | -------------------------------------- |
| GET | /api/{resource} | List all (paginated, filtered, sorted) |
| GET | /api/{resource}/:id | Get one by ID |
| POST | /api/{resource} | Create new |
| PUT | /api/{resource}/:id | Full update (replace) |
| PATCH | /api/{resource}/:id | Partial update |
| DELETE | /api/{resource}/:id | Delete by ID |
Plus:
- Swagger UI at
/api/docs— interactive API playground - Pagination —
?page=1&limit=10 - Sorting —
?sort=-createdAtor?sort=name - Filtering —
?name=John&age_gte=18 - Search —
?search=keywordacross configured fields - Field selection —
?fields=name,email - Validation — Mongoose schema validation with clear error messages
- File Uploads —
type: "File"in your schema → automatic file upload via Vercel Blob Storage - CORS enabled by default
- Timestamps —
createdAtandupdatedAtadded automatically
Installation
npm install @theutkarshdev/rapid-api-kitQuick Start
Create a file (e.g., server.js):
const { rapidAPI } = require("@theutkarshdev/rapid-api-kit");
rapidAPI({
mongoURI: "mongodb://localhost:27017/mydb",
port: 5000,
resources: [
{
name: "users",
schema: {
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
age: { type: Number },
role: { type: String, enum: ["admin", "user"], default: "user" },
},
searchBy: ["name", "email"], // Enable text search on these fields
filterBy: ["role", "age"], // Only these fields appear as filters in Swagger
},
{
name: "posts",
schema: {
title: { type: String, required: true },
body: { type: String },
author: { type: String },
published: { type: Boolean, default: false },
},
searchBy: ["title", "body", "author"], // Full-text search fields
filterBy: ["author", "published"], // Filterable in Swagger UI
},
],
});Run it:
node server.jsThat's it! Open http://localhost:5000/api/docs to see your Swagger UI.
Configuration
| Option | Type | Default | Description |
| ------------- | ------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------- |
| mongoURI | string | required | MongoDB connection string |
| port | number | 5000 | Server port |
| resources | array | required | Array of resource definitions |
| apiPrefix | string | "/api" | Base path for all endpoints |
| logging | boolean | true | Enable Morgan request logging |
| cors | object | {} | CORS options (passed to cors package) |
| swaggerInfo | object | {} | Custom Swagger title, description, version |
| blobToken | string | — | Vercel Blob read-write token. Required when any resource uses type: "File" fields |
| searchBy | array | [] | Fields for ?search= text search (case-insensitive) |
| filterBy | array | [] | Fields shown as query filters in Swagger UI. Enum/boolean → dropdown, others → text input. If omitted, all fields are filterable. |
Resource Definition
{
name: "products", // Collection name (lowercase, plural recommended)
schema: { // Mongoose schema definition
name: { type: String, required: true },
price: { type: Number, min: 0 },
category: { type: String, enum: ["electronics", "books", "clothing"] },
inStock: { type: Boolean, default: true },
tags: [String],
},
searchBy: ["name"], // Fields for ?search=keyword (case-insensitive)
filterBy: ["category", "inStock"], // Fields shown as query filters in Swagger UI
}Supported Schema Types
| Type | Example |
| --------- | ----------------------------------------- |
| String | { type: String, required: true } |
| Number | { type: Number, min: 0, max: 100 } |
| Boolean | { type: Boolean, default: false } |
| Date | { type: Date } |
| Array | [String] or { type: [String] } |
| Enum | { type: String, enum: ["a", "b", "c"] } |
File Uploads (Vercel Blob Storage)
rapid-api-kit supports file uploads out of the box. Just use type: "File" in your schema — files are automatically uploaded to Vercel Blob Storage and the public URL is stored in MongoDB.
Setup
- Create a Vercel Blob Store — Go to your Vercel dashboard → Storage → Create a Blob Store
- Get your read-write token — Copy the
BLOB_READ_WRITE_TOKENfrom the store settings - Pass it as
blobTokenin your config
Example
const { rapidAPI } = require("@theutkarshdev/rapid-api-kit");
rapidAPI({
mongoURI: "mongodb://localhost:27017/mydb",
port: 5000,
blobToken: "vercel_blob_rw_xxxxxxxxxxxx", // Your Vercel Blob read-write token
resources: [
{
name: "users",
schema: {
name: { type: String, required: true },
email: { type: String, required: true },
avatar: "File", // Simple — any file, no restrictions
resume: {
type: "File",
required: true,
maxSize: 5, // Max 5 MB
accept: ".pdf,.doc,.docx", // Only these file types
},
},
},
],
});File Field Options
| Option | Type | Default | Description |
| ---------- | ------- | ------- | ------------------------------------------------------------------------------------------------- |
| type | string | — | Must be "File" |
| required | boolean | false | Whether the file is required on create |
| maxSize | number | 10 | Maximum file size in MB |
| accept | string | — | Allowed types — same syntax as HTML <input accept="">. Examples: .pdf, image/*, image/png |
How It Works
- POST requests with file fields use
multipart/form-datainstead of JSON - Files are uploaded to Vercel Blob and the returned public URL is saved in MongoDB as a string
- PUT / PATCH — uploading a new file automatically deletes the old blob from storage
- DELETE — deleting a document automatically deletes all associated blobs
- File path format in blob storage:
{resource}/{documentId}/{field}-{timestamp}.{ext}
Uploading Files from Frontend
// Using FormData to upload files
const formData = new FormData();
formData.append("name", "John Doe");
formData.append("email", "[email protected]");
formData.append("avatar", fileInput.files[0]); // File input element
formData.append("resume", resumeInput.files[0]);
const res = await fetch("http://localhost:5000/api/users", {
method: "POST",
body: formData, // No Content-Type header — browser sets it automatically
});
const { data } = await res.json();
console.log(data.avatar); // → "https://xxxxxxxxx.public.blob.vercel-storage.com/users/abc123/avatar-1234567890.png"
console.log(data.resume); // → "https://xxxxxxxxx.public.blob.vercel-storage.com/users/abc123/resume-1234567890.pdf"Tip: You can use the
blobTokenfrom an environment variable (e.g.,process.env.BLOB_READ_WRITE_TOKEN) to keep it out of your code.
Query Examples
Pagination
GET /api/users?page=2&limit=5Sorting
GET /api/users?sort=name # ascending
GET /api/users?sort=-createdAt # descending (newest first)Search
GET /api/users?search=john # searches across searchBy fields (case-insensitive)Filtering
GET /api/users?role=admin
GET /api/users?age_gte=18&age_lte=30
GET /api/users?name=/john/ # regex search (case-insensitive)Filter operators:
field_gt— greater thanfield_gte— greater than or equalfield_lt— less thanfield_lte— less than or equalfield_ne— not equal
Field Selection
GET /api/users?fields=name,emailAPI Response Format
Success (list)
{
"success": true,
"data": [...],
"pagination": {
"total": 50,
"page": 1,
"limit": 10,
"totalPages": 5,
"hasNext": true,
"hasPrev": false
}
}Success (single)
{
"success": true,
"data": { "_id": "...", "name": "John", ... }
}Error
{
"success": false,
"error": "Validation failed",
"details": [{ "field": "email", "message": "Path `email` is required." }]
}Using with Frontend Frameworks
React (fetch)
// List all users
const res = await fetch("http://localhost:5000/api/users");
const { data } = await res.json();
// Create user
await fetch("http://localhost:5000/api/users", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "John", email: "[email protected]" }),
});Angular (HttpClient)
this.http.get("http://localhost:5000/api/users").subscribe((res) => {
this.users = res.data;
});Next.js (API route / Server Component)
const res = await fetch("http://localhost:5000/api/users", {
cache: "no-store",
});
const { data } = await res.json();Use with MongoDB Atlas (Free Cloud DB)
- Go to MongoDB Atlas and create a free cluster
- Get your connection string
- Use it:
rapidAPI({
mongoURI: "mongodb+srv://username:[email protected]/mydb",
resources: [...]
});License
MIT
