diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 00000000..ef18ffbc --- /dev/null +++ b/docs/api.md @@ -0,0 +1,43 @@ +## Serverledge API Reference + + + + + +### Registering a new function + + POST /create (registers a new function) + +##### 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 diff --git a/internal/api/api.go b/internal/api/api.go index 79cbcc63..0c2b96dd 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -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)