3.0 KiB
3.0 KiB
DMRocket API
A Node.js/Express API for managing orders with MySQL database integration.
Setup
1. Install Dependencies
npm install
2. Database Setup
Create your MySQL database and table:
CREATE DATABASE dmrocket;
USE dmrocket;
CREATE TABLE `Orders` (
`id` INT NOT NULL AUTO_INCREMENT,
`wallet` TEXT NOT NULL,
`mint` TEXT NOT NULL,
`amount` BIGINT NOT NULL DEFAULT '100',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
3. Environment Configuration
Create a .env.local file in the root directory with your database credentials:
# Database Configuration
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password_here
DB_NAME=dmrocket
DB_PORT=3306
# Server Configuration
PORT=7111
NODE_ENV=development
4. Run the Application
# Development mode
npm run dev
# Production build
npm run build
npm start
API Endpoints
All endpoints use GET requests for simplicity and ease of use.
Orders API
Create Order
- GET
/api/v1/create_order - Query Parameters:
wallet(required) - Wallet addressmint(required) - Mint addressamount(optional) - Order amount (default: 100)user_id(required) - User identifier
Example:
GET /api/v1/create_order?wallet=wallet_address&mint=mint_address&amount=200&user_id=user123
Get All Orders
- GET
/api/v1/get_all_orders
Example:
GET /api/v1/get_all_orders
Get Order by ID
- GET
/api/v1/get_order_by_id/:id
Example:
GET /api/v1/get_order_by_id/1
Get Orders by User ID
- GET
/api/v1/get_orders_by_user/:userId
Example:
GET /api/v1/get_orders_by_user/user123
Update Order
- GET
/api/v1/update_order/:id - Query Parameters: (any combination of fields)
wallet(optional) - New wallet addressmint(optional) - New mint addressamount(optional) - New amountuser_id(optional) - New user ID
Example:
GET /api/v1/update_order/1?amount=300&user_id=newuser456
Delete Order
- GET
/api/v1/delete_order/:id
Example:
GET /api/v1/delete_order/1
Health Check
- GET
/health- Returns API status and database connection status
Response Format
All API responses follow this format:
{
"success": true,
"data": {...},
"count": 1
}
Error responses:
{
"error": "Error message",
"message": "Detailed error description"
}
Database Schema
| Field | Type | Description |
|---|---|---|
| id | INT | Auto-increment primary key |
| wallet | TEXT | Wallet address |
| mint | TEXT | Mint address |
| amount | BIGINT | Order amount (default: 100) |
| created_at | DATETIME | Timestamp (auto-generated) |
| user_id | TEXT | User identifier |
Development
- TypeScript for type safety
- Express.js for the web framework
- MySQL2 for database operations
- Dotenv for environment variable management