yttcom.net · Tech · PHP Education
← Back to Guides
Guide 04

HTTP & APIs

What happens when curl calls a PHP endpoint. Requests, responses, GET, POST, and JSON — explained from scratch.

What is HTTP?

HTTP is the language browsers and servers use to talk to each other. Every time you open a webpage, your browser sends an HTTP request to a server. The server sends back an HTTP response. That exchange is HTTP.

Analogy: HTTP is like a phone call format. There are rules for how you start the call, what you say, and how you hang up. GET and POST are two different types of calls you can make.

GET vs POST — the two main request types

GET — asking for something. The data travels in the URL itself, after a ?. Used for reading.

POST — sending something. The data travels inside the request body, hidden from the URL. Used for writing, saving, or anything sensitive.

// GET — data visible in URL // https://yttcom.net/file_read.php?token=abc&file=test.txt $file = $_GET["file"]; // "test.txt" $token = $_GET["token"]; // "abc" // POST — data in request body (not in URL) // curl -X POST -F "token=abc" -F "content=hello" $token = $_POST["token"]; // "abc" $content = $_POST["content"]; // "hello"

What is an API?

API stands for Application Programming Interface. It sounds complicated but the idea is simple: an API is a PHP file (or set of PHP files) that other programs can talk to — not humans, but code.

When Builder runs a curl command to deploy a file, it is talking to the yttcom.net API. The API receives the request, does something, and sends back a structured response.

curl command on Claude's server ↓ sends POST request file_write_web.php on yttcom.net ↓ checks token, writes file JSON response back to Claude ↓ {"status":"ok","bytes":4423} Claude reads response, reports result

JSON — the language APIs speak

JSON is a simple way to structure data so that any program can read it. It uses curly braces for objects and square brackets for lists.

// A JSON response from yttcom.net looks like this: { "status": "ok", "message": "File written successfully", "bytes": 4423 } // PHP creates JSON with json_encode() $response = ["status" => "ok", "bytes" => 4423]; echo json_encode($response); // outputs: {"status":"ok","bytes":4423} // PHP reads JSON with json_decode() $raw = '{"status":"ok","bytes":4423}'; $data = json_decode($raw, true); // true = give me an array echo $data["status"]; // ok

Sending headers — setting up the response

Before PHP sends any output, it can set headers — metadata about the response. The most important ones for APIs are Content-Type (telling the caller what format the response is in) and CORS (telling the browser which websites are allowed to call this endpoint).

<?php // These MUST come before any echo or output header("Content-Type: application/json"); header("Access-Control-Allow-Origin: https://yttcom.net"); header_remove("X-Powered-By"); // hide PHP version echo json_encode(["status" => "ok"]);

HTTP status codes — the response number

Every HTTP response includes a number that tells the caller whether the request worked. You have seen these in your browser.

200 // OK — worked fine (default) 403 // Forbidden — wrong token or not allowed 404 // Not Found — file or endpoint doesn't exist 429 // Too Many Requests — rate limit hit 500 // Server Error — PHP crashed // In PHP: http_response_code(403); die(json_encode(["status" => "error", "message" => "Unauthorized"]));
The full call cycle — yttcom.net example

1. Builder runs: curl -X POST file_write_web.php -d "token=..." -d "path=..." -d "content=..."
2. yttcom.net receives the POST request
3. PHP reads $_POST["token"] and checks it
4. PHP reads $_POST["path"] and $_POST["content"]
5. PHP writes the file to disk
6. PHP sends back: {"status":"ok","bytes":4423}
7. Builder reads the response and confirms success

Every endpoint on yttcom.net follows this exact pattern.