D. Escenario con datos correctos

Versión para imprimir.

1. El usuario captura datos y activa la forma

Forma

2. Se activa el código del evento submit.

Forma

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

3. Se invoca el servicio, incluyendo los datos de la forma

Forma

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Request

POST /api/valida.php HTTP/1.1 Accept: application/json, application/problem+json
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: es-MX,es-ES;q=0.9,es;q=0.8,en;q=0.7,gl;q=0.6,pt;q=0.5
Connection: keep-alive
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
Cookie: __test=610630da28570bec7a7a24ad4391af68
Host: srvvalida.rf.gd
Origin: https://srvvalida.rf.gd
Referer: https://srvvalida.rf.gd/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
sec-ch-ua: "Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"

saludo: hola
nombre: pp
saludo=hola&nombre=pp

api/valida.php

$saludo = recibeTexto("saludo");
$nombre = recibeTexto("nombre");

if (
 $saludo === false
 || $saludo === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el saludo.",
  "type" => "/erros/faltasaludo.html"
 ]);

if (
 $nombre === false
 || $nombre === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el nombre.",
  "type" => "/errors/faltanombre.html"
 ]);

$resultado = "{$saludo} {$nombre}.";

devuelveJson($resultado);

Despierta y recibe request.

4. El servicio lee los datos

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Hace wait esperando response.

api/valida.php

$saludo = recibeTexto("saludo");
$nombre = recibeTexto("nombre");

if (
 $saludo === false
 || $saludo === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el saludo.",
  "type" => "/erros/faltasaludo.html"
 ]);

if (
 $nombre === false
 || $nombre === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el nombre.",
  "type" => "/errors/faltanombre.html"
 ]);

$resultado = "{$saludo} {$nombre}.";

devuelveJson($resultado);

Request

POST /api/valida.php HTTP/1.1 Accept: application/json, application/problem+json
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: es-MX,es-ES;q=0.9,es;q=0.8,en;q=0.7,gl;q=0.6,pt;q=0.5
Connection: keep-alive
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
Cookie: __test=610630da28570bec7a7a24ad4391af68
Host: srvvalida.rf.gd
Origin: https://srvvalida.rf.gd
Referer: https://srvvalida.rf.gd/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
sec-ch-ua: "Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"

saludo: hola
nombre: pp
saludo=hola&nombre=pp

Memoria (Servidor)

$saludo
"hola"
$nombre
"pp"

5. El servicio comprueba que el saludo sea válido

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Hace wait esperando response.

api/valida.php

$saludo = recibeTexto("saludo");
$nombre = recibeTexto("nombre");

if (
 $saludo === false
 || $saludo === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el saludo.",
  "type" => "/erros/faltasaludo.html"
 ]);

if (
 $nombre === false
 || $nombre === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el nombre.",
  "type" => "/errors/faltanombre.html"
 ]);

$resultado = "{$saludo} {$nombre}.";

devuelveJson($resultado);

Memoria (Servidor)

$saludo
"hola"
$nombre
"pp"

6. Como el saludo es válido, se comprueba que el nombre sea válido

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Hace wait esperando response.

api/valida.php

$saludo = recibeTexto("saludo");
 $nombre = recibeTexto("nombre");
 
 if (
  $saludo === false
  || $saludo === ""
 )
  throw new ProblemDetailsException([
   "status" => BAD_REQUEST,
   "title" => "Falta el saludo.",
   "type" => "/erros/faltasaludo.html"
  ]);
 
 if (
  $nombre === false
  || $nombre === ""
 )
  throw new ProblemDetailsException([
   "status" => BAD_REQUEST,
   "title" => "Falta el nombre.",
   "type" => "/errors/faltanombre.html"
  ]);
 
 $resultado = "{$saludo} {$nombre}.";
 
 devuelveJson($resultado);

Memoria (Servidor)

$saludo
"hola"
$nombre
"pp"

7. Como el nombre es válido, procesa los datos

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Hace wait esperando response.

api/valida.php

$saludo = recibeTexto("saludo");
$nombre = recibeTexto("nombre");

if (
 $saludo === false
 || $saludo === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el saludo.",
  "type" => "/erros/faltasaludo.html"
 ]);

if (
 $nombre === false
 || $nombre === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el nombre.",
  "type" => "/errors/faltanombre.html"
 ]);

$resultado = "{$saludo} {$nombre}.";

devuelveJson($resultado);

Memoria (Servidor)

$saludo
"hola"
$nombre
"pp"
$resultado
"hola pp"

8. El servicio genera la response

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Hace wait esperando response.

api/valida.php

$saludo = recibeTexto("saludo");
$nombre = recibeTexto("nombre");

if (
 $saludo === false
 || $saludo === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el saludo.",
  "type" => "/erros/faltasaludo.html"
 ]);

if (
 $nombre === false
 || $nombre === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el nombre.",
  "type" => "/errors/faltanombre.html"
 ]);

$resultado = "{$saludo} {$nombre}.";

devuelveJson($resultado);

Memoria (Servidor)

$saludo
"hola"
$nombre
"pp"
$resultado
"hola pp"

Response

HTTP/1.1 200 OK Server: openresty
Date: Mon, 18 May 2026 00:18:58 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: max-age=0
Expires: Mon, 18 May 2026 00:18:58 GMT
"Hola pp."

9. El servicio devuelve la response, que es recibida en el cliente

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Despierta y recibe response.

Response

HTTP/1.1 200 OK Server: openresty
Date: Mon, 18 May 2026 00:18:58 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: max-age=0
Expires: Mon, 18 May 2026 00:18:58 GMT
"Hola pp."

Memoria

respuesta
status
200
body
"Hola pp."
json
"Hola pp."

api/valida.php

$saludo = recibeTexto("saludo");
 $nombre = recibeTexto("nombre");
 
 if (
  $saludo === false
  || $saludo === ""
 )
  throw new ProblemDetailsException([
   "status" => BAD_REQUEST,
   "title" => "Falta el saludo.",
   "type" => "/erros/faltasaludo.html"
  ]);
 
 if (
  $nombre === false
  || $nombre === ""
 )
  throw new ProblemDetailsException([
   "status" => BAD_REQUEST,
   "title" => "Falta el nombre.",
   "type" => "/errors/faltanombre.html"
  ]);
 
 $resultado = "{$saludo} {$nombre}.";
 
 devuelveJson($resultado);

Devuelve response y se duerme.

10. Muestra el texto recibido en un alert

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Memoria

respuesta
status
200
body
"Hola pp."
json
"Hola pp."

Alert

hola pp

11. Al cerrar el alert, termina el evento

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)