|
| 1 | + |
| 2 | +# Faucet Backend API |
| 3 | + |
| 4 | +This API provides endpoints for interacting with two main tables: `faucet.solana_balances` and `faucet.rate_limits`. Below are the available endpoints for each table. |
| 5 | + |
| 6 | +--- |
| 7 | +## How to Run |
| 8 | + |
| 9 | +1. Clone the repository |
| 10 | + ```bash |
| 11 | + git clone <repository-url> |
| 12 | + ``` |
| 13 | + |
| 14 | +2. Install dependencies |
| 15 | + ```bash |
| 16 | + yarn install |
| 17 | + ``` |
| 18 | + |
| 19 | +3. Set up your `.env` file with the following |
| 20 | + ```env |
| 21 | + POSTGRES_STRING=postgresql://<user>:<password>@<host>:<port>/<database> |
| 22 | + ``` |
| 23 | + |
| 24 | +4. Start the server |
| 25 | + ```bash |
| 26 | + yarn start |
| 27 | + ``` |
| 28 | + |
| 29 | +5. Access the API at `http://localhost:3000/api`. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## Solana Balances Endpoints |
| 34 | + |
| 35 | +### **Create a New Solana Balance** |
| 36 | + |
| 37 | +**POST** `/api/solana-balances` |
| 38 | + |
| 39 | +- **Description**: Adds a new Solana account balance. |
| 40 | +- **Request Body**: |
| 41 | + ```json |
| 42 | + { |
| 43 | + "account": "string", |
| 44 | + "balance": "number" |
| 45 | + } |
| 46 | + ``` |
| 47 | +- **Curl Command**: |
| 48 | + ```bash |
| 49 | + curl -v -X POST http://localhost:3000/api/solana-balances \ |
| 50 | + -H "Content-Type: application/json" \ |
| 51 | + -d '{"account": "test_account_1", "balance": 100.50}' |
| 52 | + ``` |
| 53 | +- **Response**: |
| 54 | + ```json |
| 55 | + { |
| 56 | + "id": 1, |
| 57 | + "account": "string", |
| 58 | + "balance": "number", |
| 59 | + "date": "timestamp" |
| 60 | + } |
| 61 | + ``` |
| 62 | + |
| 63 | +### **Get All Balances for an Account** |
| 64 | + |
| 65 | +**GET** `/api/solana-balances/account/:account` |
| 66 | + |
| 67 | +- **Description**: Retrieves all balances for a specific Solana account. |
| 68 | +- **Curl Command**: |
| 69 | + ```bash |
| 70 | + curl -v http://localhost:3000/api/solana-balances/account/test_account_1 |
| 71 | + ``` |
| 72 | +- **Response**: |
| 73 | + ```json |
| 74 | + [ |
| 75 | + { |
| 76 | + "id": 1, |
| 77 | + "account": "string", |
| 78 | + "balance": "number", |
| 79 | + "date": "timestamp" |
| 80 | + }, |
| 81 | + ... |
| 82 | + ] |
| 83 | + ``` |
| 84 | + |
| 85 | +### **Get Recent Balances (Last Month)** |
| 86 | + |
| 87 | +**GET** `/api/solana-balances/recent` |
| 88 | + |
| 89 | +- **Description**: Retrieves all Solana account balances from the past month, ordered by date. |
| 90 | +- **Curl Command**: |
| 91 | + ```bash |
| 92 | + curl -v http://localhost:3000/api/solana-balances/recent |
| 93 | + ``` |
| 94 | +- **Response**: |
| 95 | + ```json |
| 96 | + [ |
| 97 | + { |
| 98 | + "account": "string", |
| 99 | + "balance": "number", |
| 100 | + "date": "timestamp" |
| 101 | + }, |
| 102 | + ... |
| 103 | + ] |
| 104 | + ``` |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Rate Limits Endpoints |
| 109 | + |
| 110 | +### **Create a New Rate Limit** |
| 111 | + |
| 112 | +**POST** `/api/rate-limits` |
| 113 | + |
| 114 | +- **Description**: Adds a new rate limit entry. |
| 115 | +- **Request Body**: |
| 116 | + ```json |
| 117 | + { |
| 118 | + "key": "string", |
| 119 | + "timestamps": ["number"] |
| 120 | + } |
| 121 | + ``` |
| 122 | +- **Curl Command**: |
| 123 | + ```bash |
| 124 | + curl -v -X POST http://localhost:3000/api/rate-limits \ |
| 125 | + -H "Content-Type: application/json" \ |
| 126 | + -d '{"key": "test_key_1", "timestamps": [1635793421]}' |
| 127 | + ``` |
| 128 | +- **Response**: |
| 129 | + ```json |
| 130 | + { |
| 131 | + "key": "string", |
| 132 | + "timestamps": ["number"] |
| 133 | + } |
| 134 | + ``` |
| 135 | + |
| 136 | +### **Get a Rate Limit by Key** |
| 137 | + |
| 138 | +**GET** `/api/rate-limits/:key` |
| 139 | + |
| 140 | +- **Description**: Retrieves the rate limit entry for a specific key. |
| 141 | +- **Curl Command**: |
| 142 | + ```bash |
| 143 | + curl -v http://localhost:3000/api/rate-limits/test_key_1 |
| 144 | + ``` |
| 145 | +- **Response**: |
| 146 | + ```json |
| 147 | + { |
| 148 | + "key": "string", |
| 149 | + "timestamps": ["number"] |
| 150 | + } |
| 151 | + ``` |
| 152 | + |
| 153 | +### **Update Timestamps for a Rate Limit** |
| 154 | + |
| 155 | +**PUT** `/api/rate-limits/:key` |
| 156 | + |
| 157 | +- **Description**: Updates the timestamps for a specific rate limit key. |
| 158 | +- **Request Body**: |
| 159 | + ```json |
| 160 | + { |
| 161 | + "timestamps": ["number"] |
| 162 | + } |
| 163 | + ``` |
| 164 | +- **Curl Command**: |
| 165 | + ```bash |
| 166 | + curl -v -X PUT http://localhost:3000/api/rate-limits/test_key_1 \ |
| 167 | + -H "Content-Type: application/json" \ |
| 168 | + -d '{"timestamps": [1635793500]}' |
| 169 | + ``` |
| 170 | +- **Response**: |
| 171 | + ```json |
| 172 | + { |
| 173 | + "key": "string", |
| 174 | + "timestamps": ["number"] |
| 175 | + } |
| 176 | + ``` |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +## Error Handling |
| 181 | + |
| 182 | +All endpoints return appropriate HTTP status codes: |
| 183 | +- `201 Created` for successful creations. |
| 184 | +- `200 OK` for successful data retrieval or updates. |
| 185 | +- `404 Not Found` if the requested resource does not exist. |
| 186 | +- `500 Internal Server Error` for unhandled exceptions. |
0 commit comments