Learn about APIs
APIs connect systems over HTTP. Learn how to host an API, schedule jobs and keep real-time connections open.
Featured
- How-to guidesHow to host an APIHosting an API means running its HTTP server around the clock at a public address with HTTPS. Step-by-step with Node.js and Python, testing and common errors.
- How-to guidesHow to host a Node.js appTo host a Node.js app, prepare package.json, read the port and secrets from the environment, pick an LTS version and run it with node. Step-by-step guide.
- How-to guidesHow to host a FastAPI, Flask or Django appTo host a FastAPI, Flask or Django app, run it with a production server (Uvicorn or Gunicorn) on 0.0.0.0. Commands, Django settings and common errors included.
Concepts7
- What is a cron job? Syntax and examplesA cron job is a task that runs on its own at times set by a five-field expression. Learn the syntax, examples, common mistakes and how to schedule jobs in Node.js.
- p50, p95 and p99 latency: what they meanp95 latency is the response time that 95% of requests stay under. Learn to calculate p50, p95 and p99, why the average misleads, and what to check when p99 rises.
- What is OpenAPI (Swagger) and how to document your APIOpenAPI is an open standard for describing an HTTP API in a YAML or JSON file. See how it relates to Swagger, a minimal example and how to generate docs and clients.
- Idempotency in APIs: what it is and how to implement itAn idempotent operation has the same effect when repeated. See which HTTP methods are idempotent and how to use the Idempotency-Key header with Redis or a database.
- What is a REST API?A REST API exposes resources at URLs and lets you act on them with HTTP methods like GET and POST. Learn the rules, status codes and a working example.
- What is a WebSocket and how does it work?A WebSocket is a protocol that keeps one connection open between client and server, with messages in both directions. See the handshake, code and when to use it.
- What is a webhookA webhook is an HTTP request a service sends to your URL when an event happens. Learn how it works, how to verify the signature, plus a Node.js example.
How-to guides15
- How to host an APIHosting an API means running its HTTP server around the clock at a public address with HTTPS. Step-by-step with Node.js and Python, testing and common errors.
- How to host a Node.js appTo host a Node.js app, prepare package.json, read the port and secrets from the environment, pick an LTS version and run it with node. Step-by-step guide.
- How to host a FastAPI, Flask or Django appTo host a FastAPI, Flask or Django app, run it with a production server (Uvicorn or Gunicorn) on 0.0.0.0. Commands, Django settings and common errors included.
- How to host a Python app or scriptTo host a Python app or script, pin the version, isolate dependencies in a venv, read secrets from the environment and handle SIGTERM. Step-by-step guide.
- How to host a SaaS: frontend, API, database and domainTo host a SaaS, deploy the frontend and API, connect a database with tenant_id and object storage for files, and point a domain with HTTPS. Step by step.
- How to host a PHP (Laravel) applicationTo host a Laravel app, set APP_KEY, install without dev packages, cache the config, run migrations and serve only the public/ folder. Step by step, with config.
- How to host a Go APITo host a Go API, read the port from PORT, listen on 0.0.0.0, build a binary for the server's OS and handle SIGTERM with a graceful shutdown. Full code included.
- How to host a Ruby on Rails applicationTo host a Rails app, use RAILS_ENV=production, pass the secret key through an env variable, tune Puma, precompile the assets and run the migrations. Step by step.
- How to host a Rust API (Axum or Actix)To host a Rust API, read the port from PORT, listen on 0.0.0.0, build with cargo build --release and handle SIGTERM. Full code for both Axum and Actix Web.
- How to host an Elixir (Phoenix) applicationTo host a Phoenix app, run with MIX_ENV=prod, read SECRET_KEY_BASE, PHX_HOST and PORT from the environment, listen on 0.0.0.0 and run mix assets.deploy first.
- How to run background jobs: queues with BullMQ and CeleryBackground jobs move slow work out of the request: the API puts a job on a Redis queue and a separate worker runs it. Examples with BullMQ and Celery.
- Production checklist for your APIA production checklist for your API: environment variables, health check, graceful shutdown, standard errors, authentication, rate limiting, CORS and logs.
- How to host a Java (Spring) or .NET APITo host a Java (Spring Boot) or .NET API, build the artifact (JAR or DLL), read the port from the environment and listen on 0.0.0.0. Step-by-step guide with code.
- How to host a WebSocket serverTo host a WebSocket server, keep the process always on, pass the Upgrade header through your proxy, send pings, and plan for what happens with several instances.
- API rate limiting: what it is and how to add itAPI rate limiting caps how many requests a client can send in a time window. Learn the algorithms, add it to a Node.js API, return 429 and test it with curl.
Problems and errors4
- CORS error (blocked by CORS policy): cause and fixA CORS error means the API did not allow your page's origin. Learn the causes, how to fix it in Express and FastAPI, and how to test the preflight with curl.
- Unexpected token < in JSON: your API returned HTMLUnexpected token '<' is not valid JSON means the response was HTML, not JSON. Learn the most common causes, how to diagnose them with curl and how to fix the code.
- EADDRINUSE and 502 after a deploy: ports, PORT and 0.0.0.0EADDRINUSE means another process already listens on the port. A 502 after a deploy comes from the app listening on localhost or the wrong port. Here is the fix.
- WebSocket connection failed: causes behind a proxy and HTTPSWebSocket connection failed means the handshake did not complete. The causes: ws:// on an HTTPS page, a proxy without Upgrade, idle timeouts, paths and instances.
Costs3
- How much does it cost to host an API?Hosting a small API costs a few to a few dozen dollars a month. See what goes into the bill (compute, database, bandwidth, requests, logs) and how to estimate it.
- Serverless or an always-on server: which is cheaperServerless charges per invocation and per GB-second; an always-on server charges a fixed fee. See the break-even math, what cold starts cost and the extras.
- How much does SaaS infrastructure cost?SaaS infrastructure adds up front end, API, database, files, email, domain, observability and AI. See the cost by stage and how each item grows with customers.
Comparisons4
- REST vs GraphQL: which to use for your APIREST exposes one URL per resource and uses HTTP caching; GraphQL has one endpoint where the client picks the fields. Compare caching, errors, N+1 and use cases.
- Cron jobs vs background workers vs queuesCron runs tasks on a clock, a worker is a process that does work in the background, and a queue holds jobs until a worker takes them. Learn when to use each.
- WebSocket vs webhook vs SSEWebSocket is a two-way channel, SSE a stream from server to browser and a webhook an HTTP notice between servers. Compare them and choose, with code examples.
- API gateway vs load balancerA load balancer spreads traffic across copies of the same app. An API gateway is the front door that authenticates, limits and routes calls. Learn when to use each.
Which to choose3
- Express, Fastify, NestJS or Hono: which Node.js framework to useExpress is the best known, Fastify focuses on speed and validation, NestJS gives teams structure and Hono runs on many runtimes. See code and which to pick.
- FastAPI, Flask or Django: which to choose for your APIFastAPI validates and documents your API from type hints, Flask is minimal and flexible, and Django ships an ORM and admin. See code, criteria and which to pick.
- Best backend language: Node.js, Python, Go, Java or RustThere is no single best: Node.js and Python ship fast, Go makes concurrency simple, Java brings the JVM and Rust gives memory control. Compare them and pick.