Crear Lambda

Crea una lambda con código fuente o contenido estático y metadatos de ruta.

Autenticación

Requiere X-Glue-Authentication.

Cuerpo de la Solicitud

Campo Tipo Descripción
name string Nombre legible de la lambda
language string javascript, static-html, static-css o static-js
code string Código fuente o contenido estático
method string Método HTTP para la ruta de la lambda
path string Path HTTP para la ruta de la lambda

Solicitud HTTP

curl -X POST "https://api.hola.cloud/api/v0/lambdas" \
  -H "X-Glue-Authentication: TU_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: TU_TOKEN
Content-Type: application/json

{
  "name": "hello-world",
  "language": "javascript",
  "method": "GET",
  "path": "/hello-world",
  "code": "export default (req) => ({ body: { message: 'Hello, World!' } })"
}
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", "TU_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(string(responseBody))
}
<?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: TU_TOKEN',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

import json

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

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

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

print(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": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

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": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

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

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

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

Ejemplo

curl -X POST "https://api.hola.cloud/api/v0/lambdas" \
  -H "X-Glue-Authentication: TU_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: TU_TOKEN
Content-Type: application/json

{
    "name": "hello-world",
    "language": "javascript",
    "method": "GET",
    "path": "/hello-world",
    "code": "export default (req) => ({ body: { message: \"Hello, World!\" } })"
  }
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", "TU_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(string(responseBody))
}
<?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: TU_TOKEN',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

import json

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

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

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

print(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": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

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": "TU_TOKEN",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

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

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

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

Respuesta

 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}

Códigos de Error

Código Descripción
400 Campos requeridos faltantes o inválidos
401 Autenticación faltante o inválida
409 Ya existe una lambda con el mismo nombre

Comentarios

Deja un comentario