endrun
v0.0.2
Published
Endrun is a simple and powerful web API framework that dynamically generates endpoints and Swagger documentation based on database models using Prisma ORM.
Downloads
10
Maintainers
Readme
Endrun
Endrun is a simple and powerful web API framework that dynamically generates endpoints and Swagger documentation based on database models using Prisma ORM.
Features
Dynamic Endpoint Generation: Automatically create endpoints for CRUD operations (GET, POST, PUT, DELETE) for each database model defined in Prisma, without the need for manual code writing.
Automatic Swagger Documentation: Generate Swagger documentation automatically for your APIs, specifying the operations available in each endpoint and the parameters required.
Prisma ORM Compatibility: Endrun works seamlessly with Prisma ORM for database management, providing a modern and efficient way to interact with your data.
Simplicity and Ease of Use: With its simple and user-friendly design, Endrun allows developers to quickly and confidently create powerful and stable APIs, without the need for repetitive code or unnecessary complexities.
Usage
To get started with Endrun, follow these simple steps:
- Install Endrun using npm:
npm install endrun dotenv prisma
vbnet Copy code
Define your database models using Prisma.
Import Endrun into your project and configure your endpoints.
Start your server and enjoy the power and simplicity of Endrun!
Example
Here's a simple example of how to use Endrun to create an API endpoint:
// index.ts
import {Endrun} from 'endrun';
import dotenv from 'dotenv';
dotenv.config();
const PORT = process.env.PORT || 3030;
new Endrun().startServer(PORT);
and add the database address in the .env file :
# .env
DATABASE_URL=postgres://postgres:postgres@localhost:5432/endrun
you can add custom routes to Endrun class :
new Endrun((router, db) => [
// base url /api
// If /products exists, it overrides it; otherwise, it creates a new endpoint.
router.get("/products", async (req, res) => {
const result = await db.product.findMany();
res.json(result);
}),
router.post("/products", async (req, res) => {
const result = await db.product.create({
data: await req.body, // An error is returned because we added that path to the withoutBodyParser !
});
res.json(result);
}),
],{
searchableModels : ["Product"],
withoutBodyParser: ["/products"]
}).startServer(PORT);