What Is an API? A Plain-English Beginner Guide With Real JSON Examples
An API (Application Programming Interface) is a structured set of rules that lets two pieces of software talk to each other automatically. Whenever a weather app fetches today's forecast, a checkout form verifies a credit card, or a travel site compares airline prices, APIs are exchanging structured data behind the scenes.
1. How a Web REST API Request Works
Most modern web APIs use HTTPâthe exact same protocol your browser uses to load web pagesâexcept instead of returning an HTML page for humans to read, the server returns compact structured data (almost always JSON) for software to parse. Every request has four basic parts:
- Endpoint URL: The address of the resource, such as
https://api.example.com/v1/rates/usd. - HTTP Method: The action you wantâ
GET(read data),POST(create new data),PUT/PATCH(update), orDELETE(remove). - Headers: Metadata like
Authorization: Bearer <token>andContent-Type: application/json. - Body (optional): The JSON payload sent with
POSTorPUTrequests.
2. Reading a Real JSON Response
{
"status": "ok",
"currency": "USD",
"rateDate": "2026-11-19",
"rates": {
"EUR": 0.92,
"GBP": 0.79,
"CAD": 1.39
}
}
3. Essential HTTP Status Codes Every Beginner Should Know
| Code | Meaning | Typical Cause |
|---|---|---|
| 200 OK / 201 Created | Success | Request succeeded or new record created |
| 400 Bad Request | Client input error | Missing required field or malformed JSON |
| 401 Unauthorized | Not authenticated | Missing, invalid, or expired API key/token |
| 403 Forbidden | No permission | Authenticated, but role lacks access |
| 404 Not Found | Resource missing | Typo in endpoint URL or deleted record ID |
| 429 Too Many Requests | Rate limited | Exceeded requests-per-minute quota |
| 500 / 502 / 503 | Server error | Bug or temporary outage on the API server |
4. Real-World Request & Response Anatomy (Headers, Auth & Rate Limits)
Every HTTP REST API call consists of four predictable parts: the Endpoint URL (e.g., https://api.example.com/v1/orders?status=paid), an HTTP Method (GET, POST, PUT, PATCH, DELETE), Request Headers (such as Authorization: Bearer <token> and Content-Type: application/json), and an optional JSON Body.
| Status Code | Meaning | How Developers Handle It |
|---|---|---|
200 OK / 201 Created | Request succeeded cleanly | Parse JSON body and update UI state |
400 Bad Request | Missing or invalid input fields | Show inline field validation errors to user |
401 / 403 | Missing/expired token or forbidden role | Refresh JWT token or redirect to sign-in |
429 Too Many Requests | API rate limit exceeded | Read Retry-After header and retry with exponential backoff |
500 / 502 / 503 | Upstream server or gateway error | Log correlation ID and show graceful retry state |
5. REST vs. GraphQL vs. Webhooks: Picking the Right Pattern
- REST APIs: Resource-based URLs returning JSONâthe universal default for public APIs, mobile backends, and cacheable CDN endpoints.
- GraphQL: Single endpoint where clients request exact nested fields, reducing over-fetching on complex dashboards at the cost of trickier HTTP caching.
- Webhooks (Reverse APIs): Instead of polling Stripe or Shopify every 5 seconds asking “did the payment finish?”, the provider sends an instant
POSTrequest to your server the moment an event occurs.
6. Frequently Asked Questions About APIs
What is an API key and why shouldn't I commit it to GitHub?
An API key identifies and bills your account. Hardcoding secret API keys inside frontend JavaScript or pushing them to public Git repositories allows automated bots to scrape them within seconds and rack up thousands of dollars in unauthorized usage. Keep secret keys strictly inside server-side environment variables.
What is CORS and why do browser API calls fail with CORS errors?
Cross-Origin Resource Sharing (CORS) is a browser security rule blocking JavaScript on Domain A from reading responses from Domain B unless Domain B explicitly sends an Access-Control-Allow-Origin header. Calling third-party APIs through your own backend proxy avoids both CORS blocks and exposed secret keys.
How can I inspect API JSON responses and JWT tokens safely?
Use our 100% browser-based JSON Formatter & Validator, JSON to TypeScript Interface Generator, and JWT Decoderâall run locally without logging your payloads on external servers.
Comments (0)
Leave A CommentNo comments yet.
Be the first to share your thoughts, questions, or review of this guide!