A lightweight, zero-dependency NPM package to interact with your public CRUD API platform. Crublibrary handles authentication, request credit tracking, and common error states, so you can focus on building your application.
npm install rohit-formpilot-crud
or using Yarn:
yarn add rohit-formpilot-crud
To use Crublibrary, please register here and generate your API_KEY and API_URL. Crublibrary retrieves your API endpoint and key from the designated environment variables. It is essential to create a .env
file in your project's root directory.
CRUD_API_URL=https://your-api-url.com
CRUD_API_KEY=your-unique-api-key
Then load them in your code (e.g., via dotenv
):
require('dotenv').config();
Import and initialize Crublibrary:
import { createCrudLibrary } from "rohit-formpilot-crud";
Setting up the API key and API URL:
const apiKey = process.env.API_KEY;
const apiUrl = process.env.API_URL;
Creating an instance of the CrudLibrary:
const crudLibrary = createCrudLibrary(apiKey, apiUrl);
- create(data)
Creates a new record.
const response = await crudLibrary.create({
value: 0.5,
txHash: '0x32424'
});
// → { id: '32872', status: 'created successfully' }
- get(id)
Retrieves a record by its ID.
const record = await crudLibrary.get('32872');
// → { id: '32872', value: 0.5, txHash: '0x32424' }
- update(id, updates)
Updates an existing record.
const result = await crudLibrary.update('32872', { value: 0.9 });
// → { status: 'updated successfully' }
- delete(id)
Deletes a record by ID.
const result = await crudLibrary.delete('32872');
// → { status: 'deleted successfully' }
-
Missing or Invalid API Key/URL
Error: Missing or invalid API credentials. Make sure CRUD_API_URL and CRUD_API_KEY are set.
-
Credit Limit Exceeded
Error: Request limit exceeded. Please recharge credits.
-
Record Not Found
Error: Record with ID '12345' not found.
-
Invalid Input
Error: Validation failed. 'value' must be a number between 0 and 1.
Since email-based recharges are simulated, when credits run out:
- The first
.create()
,.get()
,.update()
, or.delete()
call after exhaustion will return:
Error: Request limit exceeded. Please recharge credits.
- Any further attempts will also return the same error; manual recharge via emailing support is expected.
Contributions, issues, and feature requests are welcome! Please open an issue or pull request on the GitHub repo.
This project is licensed under the MIT License. See the LICENSE file for details.