|
| 1 | +# TLB Rest Server |
| 2 | + |
| 3 | +**TLB Rest Server** is an HTTP API service for parsing serialized TVM cells using a given TL-B schema. |
| 4 | + |
| 5 | +## API |
| 6 | + |
| 7 | +### POST `/parse` |
| 8 | + |
| 9 | +Parses a base64-encoded cell using the provided TL-B schema. |
| 10 | + |
| 11 | +#### Request Body |
| 12 | + |
| 13 | +| Field | Type | Required | Description | |
| 14 | +|--------|----------|----------|-----------------------------| |
| 15 | +| schema | `string` | Yes | A TL-B serialization schema | |
| 16 | +| cell | `string` | Yes | A base64-encoded cell | |
| 17 | + |
| 18 | +##### Example: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "schema": "foo$01 v:uint32 = Foo;bar$10 v:uint128 = Bar;", |
| 23 | + "cell": "te6cckEBAQEABwAACUAAAAqgsDZXlg==" |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +#### Responses |
| 28 | + |
| 29 | +* **200 OK** — successful parse: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "success": true, |
| 34 | + "result": { |
| 35 | + "parsedCell": { |
| 36 | + "kind": "Foo_foo", |
| 37 | + "v": 42 |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +``` |
| 43 | + |
| 44 | +* **400 Bad Request** — parsing failed (e.g., invalid TL-B schema or cell) |
| 45 | +* **422 Unprocessable Entity** — request body validation failed |
| 46 | +* **500 Internal Server Error** — unexpected internal error |
| 47 | + |
| 48 | +##### Example `curl` request: |
| 49 | + |
| 50 | +```bash |
| 51 | +curl -X POST http://localhost:3000/parse \ |
| 52 | + -H "Content-Type: application/json" \ |
| 53 | + -d '{"cell":"te6cckEBAQEABwAACUAAAAqgsDZXlg=="}' |
| 54 | +``` |
| 55 | + |
| 56 | +### POST `/try-parse` |
| 57 | + |
| 58 | +Attempts to parse a base64-encoded cell **without requiring a TL-B schema**. This endpoint is useful for parsing unknown cells. |
| 59 | + |
| 60 | +#### Request Body |
| 61 | + |
| 62 | +| Field | Type | Required | Description | |
| 63 | +|-------|----------|----------|-----------------------| |
| 64 | +| cell | `string` | Yes | A base64-encoded cell | |
| 65 | + |
| 66 | +##### Example: |
| 67 | + |
| 68 | +```json |
| 69 | +{ |
| 70 | + "cell": "te6cckEBAgEAywABsA+KfqUADpIH1lB9/kBfXhAIAO87mQKicbKgHIk4pSPP4k5xhHqutqYgAB7USnesDnCdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYiA7msoEBANslk4VhgAIqFqMWTE1aoxM/MRD/EEluAMqKyKvv/FAn4CTTNIDD6gjOY1bdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYsAJXpnI3GpDhSbfSWGTb/USCfMHoow3xseDEM4UCreKtluqcoI0=" |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +#### Responses |
| 75 | + |
| 76 | +* **200 OK** — successful parse: |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "success": true, |
| 81 | + "result": { |
| 82 | + "parsedCell": { |
| 83 | + "opCode": 260734629, |
| 84 | + "schema": "jettons", |
| 85 | + "internal": "jetton_transfer", |
| 86 | + "data": { |
| 87 | + "kind": "JettonTransfer", |
| 88 | + "query_id": "4101212031974910", |
| 89 | + "amount": "100000000", |
| 90 | + "destination": "EQB3ncyBUTjZUA5EnFKR5_EnOMI9V1tTEAAPaiU71gc4TiUt", |
| 91 | + "response_destination": "EQBSzBN6cnxDwDjn_IQXqgU8OJXUMcol9pxyL-yLkpKzYs9U", |
| 92 | + "custom_payload": { "kind": "Maybe_nothing" }, |
| 93 | + "forward_ton_amount": "125000000", |
| 94 | + "forward_payload": { |
| 95 | + "kind": "Either_right", |
| 96 | + "value": { "parsed": {...} } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +* **400 Bad Request** — parsing failed (e.g., invalid TL-B schema or cell) |
| 105 | +* **422 Unprocessable Entity** — request body validation failed |
| 106 | +* **500 Internal Server Error** — unexpected internal error |
| 107 | + |
| 108 | +##### Example `curl` request: |
| 109 | + |
| 110 | +```bash |
| 111 | +curl -X POST http://localhost:3000/try-parse \ |
| 112 | + -H "Content-Type: application/json" \ |
| 113 | + -d '{"cell":"te6cckEBAgEAywABsA+KfqUADpIH1lB9/kBfXhAIAO87mQKicbKgHIk4pSPP4k5xhHqutqYgAB7USnesDnCdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYiA7msoEBANslk4VhgAIqFqMWTE1aoxM/MRD/EEluAMqKyKvv/FAn4CTTNIDD6gjOY1bdABSzBN6cnxDwDjn/IQXqgU8OJXUMcol9pxyL+yLkpKzYsAJXpnI3GpDhSbfSWGTb/USCfMHoow3xseDEM4UCreKtluqcoI0="}' |
| 114 | +``` |
| 115 | + |
| 116 | +## Prometheus Metrics |
| 117 | + |
| 118 | +The service exposes metrics compatible with Prometheus. |
| 119 | + |
| 120 | +### GET `/metrics` |
| 121 | + |
| 122 | +* Exposes uptime, HTTP method/path/status metrics, and default process metrics. |
| 123 | + |
| 124 | +## Healthcheck |
| 125 | + |
| 126 | +The service exposes healthcheck endpoint. |
| 127 | + |
| 128 | +### GET `/health` |
| 129 | + |
| 130 | +* Exposes uptime and current timestamp. |
| 131 | + |
| 132 | +##### Example: |
| 133 | + |
| 134 | +```bash |
| 135 | +curl http://localhost:3000/metrics |
| 136 | +``` |
| 137 | + |
| 138 | +## Running the Service |
| 139 | + |
| 140 | +### Run with Docker |
| 141 | + |
| 142 | +To build the Docker image: |
| 143 | + |
| 144 | +```bash |
| 145 | +docker build -t app . |
| 146 | +``` |
| 147 | + |
| 148 | +To run the container: |
| 149 | + |
| 150 | +```bash |
| 151 | +docker run -e PORT=3000 -p 3000:3000 app:latest |
| 152 | +``` |
| 153 | + |
| 154 | +The app will be available at [http://localhost:3000](http://localhost:3000) |
| 155 | + |
| 156 | +### Run with Docker Compose |
| 157 | + |
| 158 | +For local development: |
| 159 | + |
| 160 | +```bash |
| 161 | +docker-compose -f docker-compose.develop.yml up |
| 162 | +``` |
| 163 | + |
| 164 | +The app will be available at [http://localhost:3000](http://localhost:3000) |
| 165 | + |
| 166 | +## Environment Variables |
| 167 | + |
| 168 | +| Variable | Description | Default | |
| 169 | +| -------- | --------------------------------- | ------- | |
| 170 | +| `PORT` | Port on which the app will listen | `3000` | |
| 171 | + |
| 172 | +## Testing |
| 173 | + |
| 174 | +### Run Tests |
| 175 | + |
| 176 | +```bash |
| 177 | +yarn test |
| 178 | +``` |
0 commit comments