Escribir Mensajes

Escribe mensajes con POST /v1/queues/{queue_id}:write.

curl -X POST "https://api.hola.cloud/v1/queues/queue_1:write" \
  -H "Content-Type: application/x-ndjson" \
  --data-binary $'{"message":"hello"}\n'
POST /v1/queues/queue_1:write HTTP/1.1
Host: api.hola.cloud
Content-Type: application/x-ndjson

${"message":"hello"}\n
package main

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

func main() {
	body := "${\"message\":\"hello\"}\\n"

	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/queues/queue_1:write", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/x-ndjson")

	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
$body = '${"message":"hello"}\\n';

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/queues/queue_1:write',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/x-ndjson',
    ],
]);

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

echo $response;
import requests

headers = {
    "Content-Type": "application/x-ndjson",
}

body = "${\"message\":\"hello\"}\\n"

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/queues/queue_1:write",
    headers=headers,
    data=body
)

print(response.text)
const body = "${\"message\":\"hello\"}\\n";

const response = await fetch("https://api.hola.cloud/v1/queues/queue_1:write", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-ndjson"
  },
  body
});

console.log(await response.text());
const body = "${\"message\":\"hello\"}\\n";

const response = await fetch("https://api.hola.cloud/v1/queues/queue_1:write", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-ndjson"
  },
  body
});

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;

public class Main {
    public static void main(String[] args) throws Exception {
        var body = """
${"message":"hello"}\n
""";

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/v1/queues/queue_1:write"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Content-Type", "application/x-ndjson")
            .build();

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

Comentarios

Deja un comentario