Skip to content

Commit

Permalink
[docs] /create documentation and minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
grussorusso committed Jun 26, 2024
1 parent 47c0ce2 commit 79e30d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Serverledge API Reference


<!--
<details>
<summary><code>POST</code> <code><b>/create</b></code> <code>(registers a new function)</code></summary>
Details
</details>
-->


### Registering a new function

<code>POST</code> <code><b>/create</b></code> <code>(registers a new function)</code>

##### Parameters

> | name | required | type | description |
> |-----------|-------------|-------------------------|------------|
> | `Name` | yes | string | Name of the function (globally unique) |
> | `Runtime` | yes | string | Base container runtime (e.g., `python310`)
> | `MemoryMB` | yes | int | Memory (in MB) reserved for each function instance
> | `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)
> | `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`
> | `TarFunctionCode` | (yes) | string | Source code package as a base64-encoded TAR archive. Not needed if `Runtime` is `custom`
> | `CustomImage` | | string | If `Runtime` is `custom`: custom container image to use

##### Responses

> | http code | content-type | response | comments |
> |---------------|-----------------------------------|---------------------------------|-----------------------------------|
> | `200` | `application/json` | `{ "Created": "function_name" }` | |
> | `404` | `text/plain` | `Invalid runtime.` | Chosen `Runtime` does not exist |
> | `409` | `text/plain` | | Function already exists |
> | `503` | `text/plain` | | Creation failed |


------------------------------------------------------------------------------------------

#### Listing existing stubs & proxy configs as YAML string
2 changes: 1 addition & 1 deletion internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func CreateFunction(c echo.Context) error {
_, ok := function.GetFunction(f.Name) // TODO: we would need a system-wide lock here...
if ok {
log.Printf("Dropping request for already existing function '%s'\n", f.Name)
return c.JSON(http.StatusConflict, "")
return c.String(http.StatusConflict, "")
}

log.Printf("New request: creation of %s\n", f.Name)
Expand Down

0 comments on commit 79e30d4

Please sign in to comment.