Send orders heartbeat
curl --request POST \
--url https://api.4casters.io/user/ordersHeartbeat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"timeout": 30
}'import requests
url = "https://api.4casters.io/user/ordersHeartbeat"
payload = { "timeout": 30 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({timeout: 30})
};
fetch('https://api.4casters.io/user/ordersHeartbeat', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.4casters.io/user/ordersHeartbeat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'timeout' => 30
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.4casters.io/user/ordersHeartbeat"
payload := strings.NewReader("{\n \"timeout\": 30\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.4casters.io/user/ordersHeartbeat")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"timeout\": 30\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.4casters.io/user/ordersHeartbeat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"timeout\": 30\n}"
response = http.request(request)
puts response.read_bodyUsuario
Heartbeat de órdenes
Autocancela tus órdenes si tu cliente se desconecta
POST
/
user
/
ordersHeartbeat
Send orders heartbeat
curl --request POST \
--url https://api.4casters.io/user/ordersHeartbeat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"timeout": 30
}'import requests
url = "https://api.4casters.io/user/ordersHeartbeat"
payload = { "timeout": 30 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({timeout: 30})
};
fetch('https://api.4casters.io/user/ordersHeartbeat', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.4casters.io/user/ordersHeartbeat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'timeout' => 30
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.4casters.io/user/ordersHeartbeat"
payload := strings.NewReader("{\n \"timeout\": 30\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.4casters.io/user/ordersHeartbeat")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"timeout\": 30\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.4casters.io/user/ordersHeartbeat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"timeout\": 30\n}"
response = http.request(request)
puts response.read_bodyUn mecanismo de seguridad: envía un heartbeat con un
timeout (en segundos). Si el siguiente heartbeat no se recibe en timeout segundos, se cancelan todas tus órdenes abiertas.
Usa este endpoint en cualquier cliente que coloque órdenes en espera: si tu proceso se cae o pierde conectividad, el heartbeat asegura que las órdenes obsoletas se retiren en lugar de quedarse en el libro.
Solicitud
POST /user/ordersHeartbeat
curl -X POST https://api.4casters.io/user/ordersHeartbeat \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"timeout": 30}'
{ "timeout": 30 }
Respuesta
La respuesta se reenvía desde el servicio de órdenes:{ "data": { /* heartbeat ack payload */ } }
Errores
| Estado | Significado |
|---|---|
400 | timeout falta, no es un número o es <= 5. |
503 | El servicio de órdenes no está disponible. |
Autorizaciones
Cuerpo
application/json
Respuesta
Heartbeat acknowledged. The response shape is forwarded from the orders service.
¿Esta página le ayudó?