Introduction
An application programming interface (API) is a defined way for one program to request data or actions from another. Web APIs commonly use HTTP, but APIs also exist within libraries, operating systems and other environments.
This is a practical, documentation-led guide. Features, costs and compatibility can change; validate vendor documentation and test with a non-sensitive example before adopting a tool.
The client-server request cycle
A client sends a request to an endpoint with a method, URL, optional headers and an optional body. A server validates the request, performs permitted work and returns an HTTP status plus a response body where appropriate.
Understand common HTTP methods
| Method | Typical purpose | Example |
|---|---|---|
| GET | Read a resource | GET /products/42 |
| POST | Submit or create | POST /orders |
| PUT | Replace a representation | PUT /profile/42 |
| PATCH | Partially update | PATCH /profile/42 |
| DELETE | Remove a resource | DELETE /sessions/42 |
Read status codes
A 2xx code generally indicates success; 4xx indicates a client-side request issue; 5xx indicates the server failed to fulfill a valid request. Never assume a response is successful merely because it contains JSON.
- 200 OK — successful response
- 201 Created — resource created
- 400 Bad Request — malformed or invalid request
- 401 Unauthorized — authentication required or invalid
- 403 Forbidden — access not permitted
- 404 Not Found — requested resource unavailable
- 429 Too Many Requests — rate limit response
- 500 Internal Server Error — server failure
JSON example
JSON is a common text format for structured data in APIs. An example product response might look like this:
{
"id": 42,
"name": "Example notebook",
"price": 12.50,
"available": true
}Make your first request
Try a public documented endpoint before handling credentials. In the terminal, use curl with an API URL you trust. Interpret the response code and headers, not just the visible JSON.
curl -i https://api.github.com/zenPagination, rate limits and retries
Large result sets are often paginated. Clients must follow pagination metadata rather than assuming one request returns everything. Respect HTTP 429 responses and documented retry guidance. Make retry behavior safe for operations that can create duplicate records.
REST, GraphQL and webhooks
REST-style APIs often organize resources around URLs and HTTP methods. GraphQL allows clients to request defined data shapes. Webhooks deliver events from a server to an endpoint you control; verify webhook signatures and design for duplicate deliveries.
Troubleshooting a failing API request
- Verify the endpoint URL and HTTP method.
- Check request headers and the expected content type.
- Confirm authentication and permissions.
- Inspect the status code and error body.
- Check rate limits and request logs.
- Reproduce with safe sample data.
FAQs
Is an API the same as a website? No; a website can use APIs. Are all APIs public? No; many require credentials. Is JSON required? No; formats vary. Does an API key identify the right permissions? Not automatically; authorization must be enforced by the server.
Research methodology and disclosure
This guide was prepared with reference to the official documentation linked below and reviewed on October 9, 2026. It does not claim hands-on comparative benchmarks, sponsored rankings or independent laboratory testing. Verify current versions, policies and prices before relying on them. Editorial image rights and attribution require owner confirmation.
Try a safe read-only request
Before adding authentication or writes, call a documented read-only endpoint in a test environment. Read the response status before parsing the body, set a timeout in the real application, and show an error that helps the user without revealing credentials. The following example illustrates the control flow; endpoint and authentication details always come from the provider's documentation.
const response = await fetch("https://api.example.test/articles/42");
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
const article = await response.json();Keep credentials and webhooks separate from browser code
A browser bundle is not a safe place for a secret API key. Put secrets in server-side environment configuration, grant only the permissions needed, and rotate or revoke a key through the provider when necessary. For webhooks, verify the provider's signature and make handlers safe to retry because delivery can be duplicated or delayed.
Related reading: Build a dependable developer toolchain, Understand RAG application architecture


