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.

skip_previous skip_next