|
| 1 | +## Serverledge API Reference |
| 2 | + |
| 3 | + |
| 4 | +<!-- |
| 5 | +
|
| 6 | +<details> |
| 7 | + <summary><code>POST</code> <code><b>/create</b></code> <code>(registers a new function)</code></summary> |
| 8 | + Details |
| 9 | +</details> |
| 10 | +--> |
| 11 | + |
| 12 | + |
| 13 | +### Registering a new function |
| 14 | + |
| 15 | + <code>POST</code> <code><b>/create</b></code> (registers a new function) |
| 16 | + |
| 17 | +##### Parameters |
| 18 | + |
| 19 | +> | name | required | type | description | |
| 20 | +> |-----------|-------------|-------------------------|------------| |
| 21 | +> | `Name` | yes | string | Name of the function (globally unique) | |
| 22 | +> | `Runtime` | yes | string | Base container runtime (e.g., `python310`) |
| 23 | +> | `MemoryMB` | yes | int | Memory (in MB) reserved for each function instance |
| 24 | +> | `CPUDemand` | | float | Max CPU cores (or fractions of) allocated to function instances (e.g., `1.0` means up to 1 core, `-1.0` means no cap) |
| 25 | +> | `Handler` | (yes) | string | Function entrypoint in the source package; syntax and semantics depend on the chosen runtime (e.g., `module.function_name`). Not needed if `Runtime` is `custom` |
| 26 | +> | `TarFunctionCode` | (yes) | string | Source code package as a base64-encoded TAR archive. Not needed if `Runtime` is `custom` |
| 27 | +> | `CustomImage` | | string | If `Runtime` is `custom`: custom container image to use |
| 28 | +
|
| 29 | + |
| 30 | +##### Responses |
| 31 | + |
| 32 | +> | http code | content-type | response | comments | |
| 33 | +> |---------------|-----------------------------------|---------------------------------|-----------------------------------| |
| 34 | +> | `200` | `application/json` | `{ "Created": "function_name" }` | | |
| 35 | +> | `404` | `text/plain` | `Invalid runtime.` | Chosen `Runtime` does not exist | |
| 36 | +> | `409` | `text/plain` | | Function already exists | |
| 37 | +> | `503` | `text/plain` | | Creation failed | |
| 38 | +
|
| 39 | + |
| 40 | + |
| 41 | +------------------------------------------------------------------------------------------ |
| 42 | +### Deleting a function |
| 43 | + |
| 44 | + <code>POST</code> <code><b>/delete</b></code> (deletes an existing function) |
| 45 | + |
| 46 | +##### Parameters |
| 47 | + |
| 48 | +> | name | required | type | description | |
| 49 | +> |-----------|-------------|-------------------------|------------| |
| 50 | +> | `Name` | yes | string | Name of the function | |
| 51 | +
|
| 52 | + |
| 53 | +##### Responses |
| 54 | + |
| 55 | +> | http code | content-type | response | comments | |
| 56 | +> |---------------|-----------------------------------|---------------------------------|-----------------------------------| |
| 57 | +> | `200` | `application/json` | `{ "Deleted": "function_name" }` | | |
| 58 | +> | `404` | `text/plain` | `Unknown function.` | The function does not exist | |
| 59 | +> | `503` | `text/plain` | | Creation failed | |
| 60 | +
|
| 61 | + |
| 62 | + |
| 63 | +------------------------------------------------------------------------------------------ |
| 64 | + |
| 65 | +### Invoking a function |
| 66 | + |
| 67 | + <code>POST</code> <code><b>/invoke/<func></b></code> (invokes function `<func>`) |
| 68 | + |
| 69 | +##### Parameters |
| 70 | + |
| 71 | +> | name | required | type | description | |
| 72 | +> |-----------|-------------|-------------------------|------------| |
| 73 | +> | `Params` | yes | dict | Key-value specification of invocation parameters | |
| 74 | +> | `CanDoOffloading` | | bool | Whether the request can be offloaded (default: true) | |
| 75 | +> | `Async` | | bool | Whether the invocation is asynchronous (default: false) | |
| 76 | +> | `QoSClass` | | int | ID of the QoS class for the request | |
| 77 | +> | `QoSMaxRespT` | | float | Desired max response time | |
| 78 | +> | `ReturnOutput` | | bool | Whether function std. output and error should be collected (if supported by the function runtime) | |
| 79 | +
|
| 80 | + |
| 81 | +##### Responses |
| 82 | + |
| 83 | +> | http code | content-type | response | comments | |
| 84 | +> |---------------|-----------------------------------|---------------------------------|-----------------------------------| |
| 85 | +> | `200` | `application/json` | *See below.* | | |
| 86 | +> | `404` | `text/plain` | `Function unknown.` | | |
| 87 | +> | `429` | `text/plain` | | Not served because of excessive load. | |
| 88 | +> | `500` | `text/plain` | | Invocation failed. | |
| 89 | +
|
| 90 | +An example response for a successful **synchronous** request: |
| 91 | + |
| 92 | + { |
| 93 | + "Success": true, |
| 94 | + "Result": "{\"IsPrime\": false}", |
| 95 | + "ResponseTime": 0.712851098, |
| 96 | + "IsWarmStart": false, |
| 97 | + "InitTime": 0.709491144, |
| 98 | + "OffloadLatency": 0, |
| 99 | + "Duration": 0.003351790000000021, |
| 100 | + "SchedAction": "" |
| 101 | + } |
| 102 | + |
| 103 | +`Result` contains the object returned by the function upon completion. |
| 104 | +The other fields provide lower-level information. For instance, `Duration` |
| 105 | +reports the execution time of the function (in seconds), excluding all the |
| 106 | +communication and initialization overheads. `IsWarmStart` indicates whether |
| 107 | +a warm container has been used for the request. |
| 108 | + |
| 109 | + |
| 110 | +An example response for a successful **asynchronous** request: |
| 111 | + |
| 112 | + { |
| 113 | + "ReqId": "isprime-98330239242748" |
| 114 | + } |
| 115 | + |
| 116 | +`ReqId` can be used later to poll the execution results. |
| 117 | + |
| 118 | +------------------------------------------------------------------------------------------ |
| 119 | +### Polling for the results of an async request |
| 120 | + |
| 121 | + <code>GET</code> <code><b>/poll/<reqId></b></code> (polls the results of `<reqId>`) |
| 122 | + |
| 123 | +##### Parameters |
| 124 | + |
| 125 | +`<reqId>` is the request identifier, as returned by `/invoke`. |
| 126 | + |
| 127 | +##### Responses |
| 128 | + |
| 129 | +> | http code | content-type | response | comments | |
| 130 | +> |---------------|-----------------------------------|---------------------------------|-----------------------------------| |
| 131 | +> | `200` | `application/json` | *See response to synchronous requests.* | | |
| 132 | +> | `404` | `text/plain` | | Results not found. | |
| 133 | +> | `500` | `text/plain` | `Could not retrieve results` | |
| 134 | +> | `500` | `text/plain` | `Failed to connect to Global Registry` | |
| 135 | +
|
| 136 | +------------------------------------------------------------------------------------------ |
| 137 | +### Prewarming a function |
| 138 | + |
| 139 | + <code>POST</code> <code><b>/prewarm</b></code> (prewarms instances for a function) |
| 140 | + |
| 141 | +##### Parameters |
| 142 | + |
| 143 | +> | name | required | type | description | |
| 144 | +> |-----------|-------------|-------------------------|------------| |
| 145 | +> | `Function` | yes | string | Name of the function | |
| 146 | +> | `Instances` | yes | int | Instances to spawn (0 to only pull the image)| |
| 147 | +> | `ForceImagePull` | | bool | Always check for image updates, even if a local copy exists | |
| 148 | +
|
| 149 | + |
| 150 | +##### Responses |
| 151 | + |
| 152 | +> | http code | content-type | response | comments | |
| 153 | +> |---------------|-----------------------------------|---------------------------------|-----------------------------------| |
| 154 | +> | `200` | `application/json` | `{ "Prewarmed": N }` | The number of prewarmed instances is returned. **It might be less than `Instances`** due to resource shortage. |
| 155 | +> | `404` | `text/plain` | `Unknown function.` | The function does not exist | |
| 156 | +> | `503` | `text/plain` | | Prewarming failed | |
| 157 | +
|
| 158 | +------------------------------------------------------------------------------------------ |
| 159 | + |
| 160 | +<!-- |
| 161 | +status API |
| 162 | +function API |
| 163 | +--> |
0 commit comments