Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

Monday, September 21, 2026

What Is an API?

// software communication

What Is an API?

An API is an interface that allows one piece of software to interact with another. It defines how requests can be made, what information can be supplied and what results can be returned.

// definition

API means Application Programming Interface

API stands for Application Programming Interface.

An API provides a defined way for software systems, applications or components to communicate.

Instead of one program needing to understand the internal code of another program, it can communicate through the interface the API exposes.

// simple idea

An API is a controlled interface

Application A ↓ API ↓ Application B

Application A does not necessarily need access to the internal workings of Application B.

It only needs to know how to use the API correctly.

// example

Imagine a weather application

A website wants to display the current temperature in London.

Instead of measuring the weather itself, it can request information from a weather service.

Website ↓ Weather API ↓ Weather service ↓ Temperature data ↓ Website

The website can then display the information returned by the API.

// request + response

Many APIs use requests and responses

A client sends a request.

The API processes the request and sends a response.

Client ↓ Request ↓ API ↓ Processing ↓ Response ↓ Client

This request-response model is extremely common in web APIs.

// web api

Web APIs communicate over networks

Many modern APIs are accessed using HTTP or HTTPS, the same fundamental protocols used by websites.

https://api.example.com/products

Software can send an HTTP request to this address and receive structured information in return.

// endpoint

What is an API endpoint?

An endpoint is a particular location exposed by an API for performing an operation or accessing a resource.

/products /products/42 /customers /orders

Different endpoints can provide access to different types of information or functionality.

// http methods

HTTP methods describe the intended operation

Method Common purpose
GET Retrieve information
POST Submit or create information
PUT Replace or update a resource
PATCH Partially update a resource
DELETE Remove a resource

The exact meaning depends on the API's design.

// get

GET can retrieve information

GET /products/42

The API might return:

{ "id": 42, "name": "Keyboard", "price": 39.99 }
// post

POST can send information

A client might create a new customer by sending:

POST /customers

with data such as:

{ "name": "Alice", "email": "alice@example.com" }

The server can validate the information, store it and return a response.

// json

APIs commonly use JSON

JSON is a convenient format for exchanging structured information between software systems.

{ "customer": { "id": 101, "name": "Alice", "active": true } }

A client can parse this data and use the individual values in its own application.

// data formats

APIs do not have to use JSON

Depending on the system, an API may exchange data using:

JSON XML HTML Plain Text Binary Data
// parameters

Requests can include parameters

Parameters allow the client to specify what it wants.

GET /weather?city=London

Here:

city=London

provides additional information to the API.

// headers

HTTP requests can contain headers

Headers carry metadata about a request or response.

Content-Type: application/json Authorization: Bearer TOKEN

Headers can specify things such as data format, authentication information and caching behaviour.

// authentication

Many APIs require authentication

An API may need to know which application or user is making a request.

Common approaches include:

API Keys Access Tokens OAuth Sessions Signed Requests

API credentials should be protected. Private keys and tokens should not normally be exposed publicly in website source code or public repositories.

// api key

What is an API key?

An API key is a value that can identify an application or account when making API requests.

API-Key: abc123...

The service can use the key to determine who is making the request and which permissions or usage limits apply.

// status codes

Web APIs often return HTTP status codes

Code General meaning
200 Request succeeded
201 Resource created
400 Problem with the request
401 Authentication required or invalid
403 Request understood but not permitted
404 Resource not found
429 Too many requests
500 Server-side error
// javascript

JavaScript can call web APIs

fetch("https://api.example.com/products") .then(response => response.json()) .then(data => { console.log(data); });

The browser sends the request, receives the response and converts the JSON into JavaScript data.

// server-side code

Server-side software can also use APIs

PHP, Python, JavaScript, Java, C# and many other languages can communicate with APIs.

Application ↓ API request ↓ External service ↓ API response ↓ Application

APIs allow systems written in completely different programming languages to work together.

// database

An API can sit between an application and a database

Website ↓ API ↓ Server application ↓ Database

The website does not need direct access to the database.

Instead, the API exposes specific operations while the server controls how the underlying data is accessed.

// controlled access

APIs can control what software is allowed to do

An application may be allowed to:

Read Products Create Orders Update Profiles Upload Files

while being prevented from directly accessing internal systems or performing unauthorised operations.

// rate limits

APIs can limit how frequently they are used

A service might allow:

1,000 requests per day

or:

100 requests per minute

These restrictions are called rate limits.

// rest

What is a REST API?

REST stands for Representational State Transfer.

It describes an architectural style for designing networked systems.

APIs described as RESTful commonly organise operations around resources and use HTTP methods such as GET, POST, PUT, PATCH and DELETE.

API and REST API are not synonyms. REST is one approach to API design. APIs can use many other architectures and protocols.

// other api styles

APIs can use different technologies

REST GraphQL SOAP RPC WebSockets

The best approach depends on the systems involved and what they need to communicate.

// important distinction

Not every API is a web API

The term API is broader than internet services.

Programming languages, operating systems, libraries and software frameworks can all expose APIs.

Browser API Operating system API Database API JavaScript API Web API Library API

In each case, the API defines how another piece of software can interact with the system.

// examples

What can APIs connect?

Payments

A website can communicate with a payment service.

Maps

An application can retrieve maps or location data.

AI

Software can send prompts or data to an AI service.

Email

Applications can send or manage messages through email services.

Accounting

Business systems can exchange invoices, transactions or customer information.

Automation

One service can trigger actions in another system.

// automation

APIs make automation possible

Suppose a customer submits an online order.

Order received ↓ Payment API ↓ Database ↓ Email API ↓ Accounting API ↓ Order completed

Multiple systems can communicate automatically without someone manually copying the information between them.

// contract

An API behaves like a software contract

The API documentation defines how another program is expected to interact with the system.

It might specify:

Endpoints Methods Parameters Authentication Data Formats Responses Errors Rate Limits

As long as both systems follow the agreed interface, their internal implementations can often change without requiring the other system to understand those details.

// advantages

Why are APIs so useful?

Integration

Different software systems can work together.

Automation

Information can move between systems automatically.

Abstraction

Applications can use functionality without knowing every internal implementation detail.

Reuse

The same service can support websites, mobile apps, internal tools and other software.

// mental model

The simplest way to think about an API

Your software ↓ "Please do this" ↓ API ↓ Other software ↓ Result ↓ Your software

The API defines the rules for that conversation.

// summary

Software talking to software.

An API is an Application Programming Interface: a defined way for software systems to interact. APIs can expose data and functionality through requests, responses, endpoints and documented rules, making them fundamental to integrations, automation, websites, applications and modern software systems.

Friday, September 18, 2026

What Is PHP?

// server-side programming

What Is PHP?

PHP is a programming language widely used for server-side web development. It can generate web pages, process forms, communicate with databases, manage sessions and build dynamic websites and applications.

// definition

PHP is a server-side scripting language

PHP is a general-purpose programming language particularly suited to web development.

PHP code commonly runs on a web server rather than directly inside the user's browser.

The server executes the PHP code and sends the resulting output, often HTML, back to the browser.

// name

What does PHP stand for?

PHP is officially described using the recursive acronym:

PHP: Hypertext Preprocessor

The name reflects PHP's long association with generating and processing web content.

// example

What does PHP look like?

<?php echo "Hello, world!"; ?>

The echo statement sends text to the output.

In a web application, that output can become part of the HTML returned to the browser.

// server

PHP usually runs before the page reaches the browser

Browser requests page ↓ Web server receives request ↓ PHP code executes ↓ PHP generates output ↓ Server sends response ↓ Browser displays page

The browser usually receives the output generated by PHP rather than the original PHP source code.

// php + html

PHP can be embedded inside HTML

<h1>Welcome</h1> <p> Today is <?php echo date("d F Y"); ?> </p>

PHP executes on the server and inserts the generated value into the document before it is sent to the user.

// variables

PHP can store information in variables

<?php $name = "Alice"; $orders = 4; echo $name; echo $orders; ?>

PHP variable names normally begin with a $ symbol.

// data types

PHP supports different kinds of data

Type Example
String "Freelance Coder"
Integer 42
Float 19.99
Boolean true
Array ["HTML", "CSS", "PHP"]
Null null
Object new Customer()
// arrays

PHP arrays can store collections of data

<?php $skills = [ "HTML", "CSS", "JavaScript", "PHP" ]; echo $skills[0]; ?>

This outputs:

HTML
// associative arrays

PHP arrays can also use named keys

<?php $customer = [ "name" => "Alice", "orders" => 4, "active" => true ]; echo $customer["name"]; ?>

Associative arrays are useful for representing structured information using named keys and values.

// conditions

PHP can make decisions

<?php $loggedIn = true; if ($loggedIn) { echo "Welcome back."; } else { echo "Please sign in."; } ?>

Conditional statements allow different code to run depending on the state of the application.

// functions

PHP functions package reusable logic

<?php function greet($name) { return "Hello, " . $name; } echo greet("Alice"); ?>

The full stop operator joins strings together in PHP.

// loops

PHP can repeat tasks

<?php for ($i = 1; $i <= 5; $i++) { echo $i; } ?>

Loops are useful when the same operation must be repeated several times.

// foreach

foreach is useful for collections

<?php $skills = [ "HTML", "CSS", "PHP" ]; foreach ($skills as $skill) { echo $skill; } ?>

The loop processes each item in the array one at a time.

// forms

PHP can process form submissions

A website might contain a form:

<form method="post"> <input type="text" name="name" > <button type="submit"> Send </button> </form>

PHP can receive the submitted data:

<?php if ($_SERVER["REQUEST_METHOD"] === "POST") { $name = $_POST["name"] ?? ""; } ?>

User input should be validated and handled safely. Real applications should never assume that submitted information is automatically trustworthy.

// databases

PHP can communicate with databases

PHP is commonly used with relational databases such as MySQL and PostgreSQL.

An application might use a database to store:

Users Products Orders Blog Posts Settings Transactions
// database connection

PHP provides database interfaces

One common approach is PHP Data Objects, or PDO.

<?php $pdo = new PDO( "mysql:host=localhost;dbname=shop;charset=utf8mb4", $username, $password ); ?>

Applications can then execute database queries through the connection.

// sql safety

Prepared statements are important

<?php $stmt = $pdo->prepare( "SELECT * FROM users WHERE email = ?" ); $stmt->execute([$email]); $user = $stmt->fetch(); ?>

Prepared statements allow values to be supplied separately from the SQL structure and are an important defence against SQL injection.

// sessions

PHP can maintain session data

<?php session_start(); $_SESSION["user_id"] = 123; ?>

Sessions allow a server to associate information with a user across multiple requests.

They are commonly used for login systems and other stateful website features.

// cookies

PHP can also work with cookies

<?php setcookie( "theme", "light", time() + 3600 ); ?>

Cookies are stored by the browser and can later be sent back to the server with requests.

// json

PHP works with JSON

PHP can convert arrays and objects into JSON:

<?php $data = [ "name" => "Alice", "orders" => 4 ]; echo json_encode($data); ?>

It can also convert JSON into PHP data:

<?php $data = json_decode( $json, true ); ?>

This makes PHP useful for building and consuming APIs.

// APIs

PHP can power APIs

Instead of returning an HTML page, a PHP application can return structured data.

<?php header( "Content-Type: application/json" ); echo json_encode([ "status" => "success", "message" => "Data received" ]); ?>

Another application can then consume the JSON response.

// php vs javascript

PHP and JavaScript often work together

PHP

Commonly runs on the server and handles server-side application logic.

JavaScript

Commonly runs in the browser and handles interactive client-side behaviour.

PHP Output

Can generate HTML or JSON that is sent to the browser.

JavaScript Requests

Can send requests to PHP-powered APIs and process their responses.

// web application

A PHP web application might work like this

User ↓ Browser ↓ HTTP request ↓ Web server ↓ PHP application ↓ Database ↓ PHP generates response ↓ HTML or JSON ↓ Browser

PHP often acts as the server-side layer connecting users, application logic and stored data.

// wordpress

WordPress is built with PHP

PHP has played a major role in the development of content management systems.

WordPress uses PHP extensively for themes, plugins, templates, database interaction and server-side logic.

<?php the_title(); the_content(); ?>

WordPress-specific PHP functions can dynamically retrieve and display website content.

// .php files

PHP code is commonly stored in .php files

index.php contact.php login.php api.php functions.php

A web server configured for PHP can execute the PHP code when one of these files is requested.

// security

Server-side code must handle data carefully

PHP applications often process passwords, form inputs, database queries, cookies and uploaded files.

Secure applications therefore need appropriate validation, escaping, authentication and database practices.

Never trust input simply because it came from your own website. Server-side code should validate data and apply the correct security controls for how that data will be used.

// frameworks

PHP has a large software ecosystem

Developers can use frameworks and content management systems rather than building every component from scratch.

Laravel Symfony WordPress Composer PHPUnit
// uses

What is PHP used for?

Dynamic Websites WordPress APIs Databases Forms Authentication E-commerce Web Applications Server-Side Logic Automation
// summary

The server does the work.

PHP is a programming language widely used for server-side web development. It can generate HTML, process forms, manage sessions, communicate with databases, work with JSON and APIs, and power dynamic websites and applications such as WordPress.

What Is JavaScript?

// programming

What Is JavaScript?

JavaScript is a programming language used extensively on the web. It allows websites to respond to users, manipulate page content, communicate with servers, process data and perform tasks dynamically.

// definition

JavaScript adds logic and behaviour

JavaScript is a high-level programming language used in web browsers, servers and many other software environments.

On a web page, JavaScript can react to user actions, change HTML content, modify CSS styles, process data and communicate with APIs.

It is one of the core technologies of modern web development alongside HTML and CSS.

// example

What does JavaScript look like?

A very simple JavaScript statement might be:

console.log("Hello, world!");

This tells JavaScript to send the text Hello, world! to the developer console.

// variables

JavaScript can store information

Variables allow programs to store values for later use.

let name = "Alice"; let orders = 4; console.log(name); console.log(orders);

Here, one variable stores text and another stores a number.

// let + const

Values can be declared with let and const

let score = 10; score = 20; const siteName = "Freelance Coder";

let is commonly used when a variable may later be assigned another value.

const creates a binding that cannot later be reassigned.

// data types

JavaScript works with different kinds of data

Type Example
String "Freelance Coder"
Number 42
Boolean true
Undefined undefined
Null null
Object { name: "Alice" }
BigInt 123n
Symbol Symbol("id")
// arrays

Arrays store collections of values

const skills = [ "HTML", "CSS", "JavaScript", "PHP" ];

Individual values can be accessed by their position.

console.log(skills[0]);

This produces:

HTML

JavaScript array indexes begin at 0. The first item therefore has index 0 rather than 1.

// objects

Objects group related information

const customer = { name: "Alice", orders: 4, active: true };

The object's properties can then be accessed:

console.log(customer.name);

This produces:

Alice
// operators

JavaScript can perform calculations

let a = 10; let b = 5; let total = a + b; console.log(total);

The result is:

15
+ - * / % **
// conditions

Programs can make decisions

Conditional statements allow code to behave differently depending on whether a condition is true or false.

const loggedIn = true; if (loggedIn) { console.log("Welcome back."); } else { console.log("Please sign in."); }
// functions

Functions package reusable behaviour

function greet(name) { return "Hello, " + name; } console.log(greet("Alice"));

The function receives a value, performs some logic and returns a result.

This makes code easier to organise and reuse.

// arrow functions

JavaScript also has arrow functions

const add = (a, b) => { return a + b; }; console.log(add(3, 4));

This outputs:

7
// loops

JavaScript can repeat tasks

for (let i = 1; i <= 5; i++) { console.log(i); }

This repeats the same instruction while the loop condition remains true.

// dom

JavaScript can change a web page

In a browser, JavaScript can interact with the Document Object Model, usually called the DOM.

Suppose the HTML contains:

<h1 id="title">Old Title</h1>

JavaScript could change it:

document.getElementById("title").textContent = "New Title";

The visible heading can change without loading an entirely new HTML document.

// events

JavaScript can respond to users

Browsers generate events when users click buttons, type into forms, move the mouse and perform other actions.

const button = document.getElementById("button"); button.addEventListener("click", function () { alert("Button clicked!"); });

JavaScript waits for the click event and then runs the function.

// html + css + javascript

The three core web technologies have different roles

HTML

Defines the structure and meaning of the page.

CSS

Controls presentation, layout and visual design.

JavaScript

Adds logic, behaviour and interactivity.

Together

They form the foundation of much of modern front-end web development.

// example

HTML, CSS and JavaScript working together

HTML:

<button id="helloButton"> Say Hello </button>

CSS:

#helloButton { background: #001eff; color: white; padding: 12px 18px; }

JavaScript:

document .getElementById("helloButton") .addEventListener("click", function () { alert("Hello!"); });

HTML creates the button, CSS styles it and JavaScript gives it behaviour.

// APIs

JavaScript can communicate with APIs

JavaScript can request data from another service over the web.

fetch("https://api.example.com/products") .then(response => response.json()) .then(data => { console.log(data); });

This example requests information from an API and converts the response into JavaScript data.

// javascript + json

JavaScript works naturally with JSON

JSON was derived from JavaScript object notation and is widely used to exchange structured information.

{ "name": "Alice", "orders": 4 }

JavaScript can parse JSON text:

const customer = JSON.parse(jsonText);

It can also convert JavaScript values into JSON:

const json = JSON.stringify(customer);
// asynchronous code

JavaScript can handle asynchronous tasks

Some operations take time, such as requesting information from a server.

JavaScript provides mechanisms such as promises and async/await for working with these tasks.

async function getData() { const response = await fetch("/api/data"); const data = await response.json(); console.log(data); }
// runtime

JavaScript is not limited to browsers

JavaScript originally became popular as a browser language, but it can now run in many other environments.

Web Browsers Servers Node.js Web Apps Desktop Apps Automation Cloud Functions
// node.js

Node.js allows JavaScript to run outside the browser

Node.js is a JavaScript runtime commonly used for server-side programming, command-line tools and automation.

console.log( "JavaScript running with Node.js" );

This means the same language can be used for both browser-based and server-side development.

// javascript vs java

JavaScript is not Java

JavaScript and Java are different programming languages. Despite the similarity in their names, they have different histories, syntax, ecosystems and execution models.

// dynamic typing

JavaScript is dynamically typed

A variable can hold values of different types at different times.

let value = 10; value = "Hello"; value = true;

The variable itself is not permanently restricted to one of these types.

// modules

JavaScript code can be divided into modules

Larger applications can separate functionality into reusable files.

export function add(a, b) { return a + b; }

Another JavaScript file can import that function:

import { add } from "./math.js"; console.log(add(2, 3));
// uses

What is JavaScript used for?

Interactive Websites Web Applications APIs Data Processing Automation Servers Forms Animations AI Interfaces Browser Tools
// summary

Structure and design become interactive.

JavaScript is a programming language used to add logic, behaviour and interactivity to websites and applications. It can manipulate HTML, change CSS, process data, respond to users, communicate with APIs and run on both browsers and servers.

What Is JSON?

// data formats

What Is JSON?

JSON is a lightweight text-based format for representing structured data. It is widely used by websites, APIs, applications and programming languages to exchange information in a form that is relatively easy for both humans and computers to understand.

// definition

JSON means JavaScript Object Notation

JSON stands for JavaScript Object Notation.

It is a text-based format used to represent structured information using objects, arrays, names and values.

Although JSON originated from JavaScript syntax, it is now used independently by many programming languages and software systems.

// example

What does JSON look like?

Suppose we want to store information about a customer.

{ "name": "Alice Smith", "email": "alice@example.com", "orders": 4, "active": true }

This is a JSON object.

Each piece of information consists of a name and a value.

// name-value pairs

JSON uses name-value pairs

Consider this line:

"name": "Alice Smith"

The name of the property is:

"name"

and its value is:

"Alice Smith"

A colon separates the property name from its value. Commas separate different properties.

// objects

JSON objects use curly braces

An object begins with { and ends with }.

{ "product": "Keyboard", "price": 49.99, "stock": 12 }

Objects are useful when several named properties belong to the same thing.

// arrays

JSON arrays use square brackets

An array represents an ordered collection of values.

[ "HTML", "CSS", "JavaScript", "PHP" ]

Arrays begin with [ and end with ].

// collections

Arrays can contain objects

This is extremely common when working with APIs and databases.

[ { "name": "Alice", "orders": 4 }, { "name": "Ben", "orders": 7 }, { "name": "Carla", "orders": 2 } ]

Here, the array contains three separate customer objects.

// data types

JSON supports several kinds of values

Type Example
String "Freelance Coder"
Number 42
Boolean true
Null null
Object { "name": "Alice" }
Array [1, 2, 3]
// strings

JSON strings use double quotation marks

{ "city": "London" }

JSON requires strings and property names to use double quotation marks.

Important: JSON does not allow property names or strings to be written using single quotation marks in standard JSON syntax.

// boolean values

JSON can represent true and false

{ "active": true, "verified": false }

Boolean values are written without quotation marks.

// null

JSON can represent no value

{ "middleName": null }

The value null represents the intentional absence of a value.

// nesting

JSON can represent complex structures

Objects can contain other objects and arrays.

{ "customer": { "name": "Alice", "location": { "city": "Birmingham", "country": "United Kingdom" }, "orders": [ { "id": 1001, "total": 49.99 }, { "id": 1002, "total": 25.50 } ] } }

This creates a hierarchical structure in which related information can be grouped together.

// APIs

JSON is widely used by APIs

One of JSON's most important uses is transferring data between software systems.

For example, an application might request information about a product from an API and receive:

{ "id": 1042, "name": "Wireless Keyboard", "price": 39.99, "available": true }

The application can then read the JSON and use the values in its own interface or processing.

// data exchange

JSON helps systems communicate

Website ↓ API request ↓ Server ↓ JSON response ↓ Website

JSON provides a common structure that both sides can understand.

// json vs csv

JSON and CSV solve different problems

CSV works particularly well for simple tabular data.

Name,Orders Alice,4 Ben,7

JSON can represent more complex nested structures.

{ "customers": [ { "name": "Alice", "orders": [ 1001, 1002 ] } ] }
CSV JSON
Rows and columns Objects and arrays
Excellent for tables Excellent for structured data
Flat structure Can be nested
// json vs xml

JSON and XML can represent similar data

This XML:

<customer> <name>Alice</name> <orders>4</orders> </customer>

could be represented in JSON as:

{ "customer": { "name": "Alice", "orders": 4 } }

JSON is often more compact for application data, while XML provides additional features that can be useful for document-oriented and specialised systems.

// plain text

JSON is a text format

JSON may represent complex information, but the underlying document is still text.

This means JSON can be opened in a text editor, transmitted over a network and processed by many different programming languages.

Text-Based Structured Portable Machine-Readable Human-Readable
// utf-8

JSON and UTF-8

JSON exchanged between systems is commonly encoded using UTF-8.

{ "name": "João", "currency": "£", "symbol": "π", "message": "Olá" }

UTF-8 allows JSON to represent a very wide range of Unicode characters reliably.

// .json files

JSON can be stored in .json files

JSON data saved as a standalone file normally uses the .json file extension.

customers.json products.json settings.json data.json

JSON does not have to exist as a separate file, however. It can also be sent directly between applications and APIs.

// advantages

Why is JSON so widely used?

Readable

Its structure is relatively easy for people to inspect and understand.

Lightweight

JSON can represent structured information without large amounts of additional markup.

Structured

Objects, arrays and nested values can represent sophisticated data structures.

Widely supported

Most modern programming languages and web technologies can read and generate JSON.

// uses

Where is JSON used?

APIs Web Applications Databases Configuration Automation AI Systems Data Exchange JavaScript Mobile Apps Cloud Services
// syntax

JSON syntax is strict

Valid JSON must follow specific rules.

Property names use double quotes.

Strings use double quotes.

Properties are separated by commas.

Trailing commas are not permitted in standard JSON.

For example, this is valid:

{ "name": "Alice", "age": 30 }

But this is not valid standard JSON:

{ 'name': 'Alice', 'age': 30, }
// summary

Simple text. Structured information.

JSON is a text-based format for representing structured data using objects, arrays and name-value pairs. Its simplicity, flexibility and widespread software support make it one of the most important formats for APIs, websites, applications, automation and modern data exchange.

What Is an IP Address?

// networking What Is an IP Address? An IP address is a numerical address used t...