Create Lambda

Creates a lambda with source code or static content and route metadata.

Authentication

Requires X-Glue-Authentication.

Request Body

Field Type Description
name string Human-readable lambda name
language string javascript, static-html, static-css, or static-js
code string Source code or static content
method string HTTP method for the lambda route
path string HTTP path for the lambda route

HTTP Request

curl -X POST "https://api.hola.cloud/api/v0/lambdas" \
  -H "X-Glue-Authentication: YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "hello-world",
  "language": "javascript",
  "method": "GET",
  "path": "/hello-world",
  "code": "export default (req) => ({ body: { message: '\''Hello, World!'\'' } })"
}'
POST /api/v0/lambdas HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: YOUR_TOKEN
Content-Type: application/json

{
  "name": "hello-world",
  "language": "javascript",
  "method": "GET",
  "path": "/hello-world",
  "code": "export default (req) => ({ body: { message: 'Hello, World!' } })"
}
// Go 1.21+, standard library only. Save as main.go and run: go run main.go
package main

import (
	"fmt"
	"io"
	"net/http"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"code": "export default (req) => ({ body: { message: 'Hello, World!' } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://api.hola.cloud/api/v0/lambdas", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "YOUR_TOKEN")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Status)
	fmt.Println(string(responseBody))
}
<?php
// PHP 8+ with the curl extension. Save as example.php and run: php example.php

$payload = ['code' => 'export default (req) => ({ body: { message: \'Hello, World!\' } })', 'language' => 'javascript', 'method' => 'GET', 'name' => 'hello-world', 'path' => '/hello-world'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/api/v0/lambdas',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: YOUR_TOKEN',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $response, "\n";
curl_close($ch);
# Python 3.8+. Install: pip install requests. Save as example.py and run: python example.py
import requests

headers = {
    "X-Glue-Authentication": "YOUR_TOKEN",
    "Content-Type": "application/json",
}

payload = {"code": "export default (req) => ({ body: { message: 'Hello, World!' } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"}

response = requests.request(
    "POST",
    "https://api.hola.cloud/api/v0/lambdas",
    headers=headers,
    json=payload
)

print(response.status_code)
print(response.text)
// Node.js 18+. Save as example.mjs and run: node example.mjs
const payload = {"code": "export default (req) => ({ body: { message: 'Hello, World!' } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas", {
  method: "POST",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(response.status);
console.log(await response.text());
const payload = {"code": "export default (req) => ({ body: { message: 'Hello, World!' } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas", {
  method: "POST",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(response.status);
console.log(await response.text());
// Java 17+, standard library only. Save as Main.java and run: java Main.java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        var body = """
{
  "name": "hello-world",
  "language": "javascript",
  "method": "GET",
  "path": "/hello-world",
  "code": "export default (req) => ({ body: { message: 'Hello, World!' } })"
}
""";

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/api/v0/lambdas"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("X-Glue-Authentication", "YOUR_TOKEN")
            .header("Content-Type", "application/json")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode());
        System.out.println(response.body());
    }
}

Example

curl -X POST "https://api.hola.cloud/api/v0/lambdas" \
  -H "X-Glue-Authentication: YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "hello-world",
    "language": "javascript",
    "method": "GET",
    "path": "/hello-world",
    "code": "export default (req) => ({ body: { message: \"Hello, World!\" } })"
  }'
POST /api/v0/lambdas HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: YOUR_TOKEN
Content-Type: application/json

{
    "name": "hello-world",
    "language": "javascript",
    "method": "GET",
    "path": "/hello-world",
    "code": "export default (req) => ({ body: { message: \"Hello, World!\" } })"
  }
// Go 1.21+, standard library only. Save as main.go and run: go run main.go
package main

import (
	"fmt"
	"io"
	"net/http"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"code": "export default (req) => ({ body: { message: \"Hello, World!\" } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://api.hola.cloud/api/v0/lambdas", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "YOUR_TOKEN")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.Status)
	fmt.Println(string(responseBody))
}
<?php
// PHP 8+ with the curl extension. Save as example.php and run: php example.php

$payload = ['code' => 'export default (req) => ({ body: { message: "Hello, World!" } })', 'language' => 'javascript', 'method' => 'GET', 'name' => 'hello-world', 'path' => '/hello-world'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/api/v0/lambdas',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: YOUR_TOKEN',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $response, "\n";
curl_close($ch);
# Python 3.8+. Install: pip install requests. Save as example.py and run: python example.py
import requests

headers = {
    "X-Glue-Authentication": "YOUR_TOKEN",
    "Content-Type": "application/json",
}

payload = {"code": "export default (req) => ({ body: { message: \"Hello, World!\" } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"}

response = requests.request(
    "POST",
    "https://api.hola.cloud/api/v0/lambdas",
    headers=headers,
    json=payload
)

print(response.status_code)
print(response.text)
// Node.js 18+. Save as example.mjs and run: node example.mjs
const payload = {"code": "export default (req) => ({ body: { message: \"Hello, World!\" } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas", {
  method: "POST",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(response.status);
console.log(await response.text());
const payload = {"code": "export default (req) => ({ body: { message: \"Hello, World!\" } })", "language": "javascript", "method": "GET", "name": "hello-world", "path": "/hello-world"};

const response = await fetch("https://api.hola.cloud/api/v0/lambdas", {
  method: "POST",
  headers: {
    "X-Glue-Authentication": "YOUR_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(response.status);
console.log(await response.text());
// Java 17+, standard library only. Save as Main.java and run: java Main.java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        var body = """
{
    "name": "hello-world",
    "language": "javascript",
    "method": "GET",
    "path": "/hello-world",
    "code": "export default (req) => ({ body: { message: \"Hello, World!\" } })"
  }
""";

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/api/v0/lambdas"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("X-Glue-Authentication", "YOUR_TOKEN")
            .header("Content-Type", "application/json")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode());
        System.out.println(response.body());
    }
}

Response

 1{
 2  "id": "f1a2b3c4-d5e6-7890-abcd-ef0123456789",
 3  "created_timestamp": 1751378400,
 4  "owner": "user_123",
 5  "project_id": "project_456",
 6  "name": "hello-world",
 7  "language": "javascript",
 8  "code": "export default (req) => ({ body: { message: \"Hello, World!\" } })",
 9  "method": "GET",
10  "path": "/hello-world"
11}

Error Codes

Code Description
400 Missing or invalid required fields
401 Missing or invalid authentication
409 A lambda with the same name already exists

Comments

Leave a comment