REST, GraphQL & Webhook API Examples for Developers

Written by

in

API Examples: How Modern Software Talks Behind the Scenes

Every time you check morning rain radar, split a dinner bill with a payment app, or log into a side project using an existing account, an Application Programming Interface (API) does the heavy lifting. Instead of building every piece of data or logic from scratch, software sends a structured request over a network and receives a structured answer.


1. Public Data APIs: Weather and Geolocation

Public data APIs expose real-world measurements or reference datasets over standard HTTP endpoints. A running app or weather dashboard might query a forecast endpoint with latitude, longitude, and desired units, then parse the JSON payload to render icons and temperatures.

GET https://api.example.com/v1/forecast?lat=-37.8136&lon=144.9631&units=metric HTTP/1.1
Host: api.example.com
Accept: application/json
{
  "location": {
    "city": "Melbourne",
    "country": "AU"
  },
  "current": {
    "temperature_c": 19.4,
    "condition": "Partly cloudy",
    "precipitation_mm": 0.0
  }
}

Why this pattern works: The client does not need direct access to meteorological sensors or proprietary forecast models. It only needs to understand the endpoint contract, query parameters, and response fields.


2. Transactional APIs: Payments and Idempotency

Payment and checkout APIs handle money movement, ledger updates, and fraud checks. Unlike a read-only weather lookup, charging a card changes real state—so reliability and safety rules are stricter.

POST https://api.payments.example.com/v1/charges HTTP/1.1
Host: api.payments.example.com
Authorization: Bearer sk_live_demo_token
Idempotency-Key: order-98412-attempt-1
Content-Type: application/json

{
  "amount_cents": 4500,
  "currency": "AUD",
  "customer_id": "cus_7721",
  "description": "Annual subscription"
}
{
  "charge_id": "ch_509182",
  "status": "succeeded",
  "amount_cents": 4500,
  "currency": "AUD"
}

Key safeguard: Notice the Idempotency-Key header. If a mobile network drops right after a payment succeeds and the app retries the request, the server recognizes the key and returns the original result instead of double-charging the customer.


3. Event-Driven APIs: Webhooks for Real-Time Updates

Polling an API every few seconds wastes bandwidth when nothing has changed. Webhooks invert the flow: your app registers a callback URL, and the external service sends an HTTP POST request to your server the moment an event happens—such as a completed payout, shipped parcel, or failed invoice.

{
  "event_id": "evt_30194",
  "event_type": "shipment.delivered",
  "occurred_at": "2026-11-26T01:45:00Z",
  "data": {
    "shipment_id": "shp_8842",
    "carrier": "AusPost Express",
    "signed_by": "Front desk"
  }
}

Key safeguard: Because anyone on the internet can send a POST request to a public webhook URL, receivers verify a cryptographic signature header before trusting the payload.


4. Browser and Local APIs: No Network Required

Not every API crosses the internet. Web browsers ship with built-in JavaScript APIs that let web apps interact with hardware, storage, or browser tabs directly on the user’s device.

  • Geolocation API (navigator.geolocation): Prompts the user for permission and reads current coordinates for nearby map results.
  • Clipboard API (navigator.clipboard): Copies or reads text safely after explicit user interaction.
  • Web Storage API (localStorage): Saves small key-value preferences (such as dark mode or sort order) across page reloads.

Comparing Common API Styles

API Pattern Direction of Initiation Typical Use Case Key Design Concern
REST over HTTP Client initiates request CRUD apps, mobile backends, public data Clear resource URLs, status codes, rate limits
Webhooks Provider pushes event Payment confirmations, order status, CI builds Signature verification, retry handling
Browser / Device APIs Page script calls runtime Maps, clipboard actions, local UI state User permission prompts, origin isolation

Practical Checklist Before Integrating Any API

  1. Read the rate-limit and error rules first: Check how the API signals throttling (often HTTP 429) and how long to back off before retrying.
  2. Validate responses defensively: Treat external fields as untrusted input—handle missing optional keys, unexpected null values, and time zones explicitly.
  3. Keep secrets off client code: Never embed private API keys or payment secret tokens inside browser JavaScript or mobile app binaries; route secret calls through your own backend server.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *