# HTTP, REST APIs and JSON

> Model providers are HTTP APIs; understand requests, headers, status codes, JSON bodies and how to build a small API of your own. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/http-apis-json
Last updated: 2026-11-28

Model providers are HTTP APIs; understand requests, headers, status codes, JSON bodies and how to build a small API of your own.

Beginner · about 10 hours · difficulty 2/5

Under every SDK call to a model is a plain **HTTPS request** with a JSON body and an API key header. When something breaks (a 429, a timeout, a malformed body) you debug at the HTTP level, so this layer needs to be familiar.

### Core concepts

- **Methods and status codes**: GET vs POST; 2xx success, 4xx your fault (400 bad request, 401 bad key, 429 rate limited), 5xx their fault (500, 503, overloaded).
- **Headers**: `Authorization` or provider-specific key headers, `Content-Type: application/json`, and rate limit headers that tell you how much budget is left.
- **JSON**: nested objects and arrays, escaping, and the difference between a JSON string and a parsed object.
- **Timeouts and retries**: LLM calls can take many seconds. Set explicit timeouts and retry only on retryable errors (429, 5xx) with exponential backoff.
- **Server-Sent Events (SSE)**: the streaming format most model APIs use to send tokens as they are generated.

### Building your own API

You will wrap model calls behind your own endpoint so that keys stay on the server. Learn one framework: **FastAPI** (Python) or Express/Hono (TypeScript). Understand request validation, returning errors with proper status codes, and CORS for browser clients.

### Good enough to move on

You can call an API with `curl` and from code, read the status code and headers, and expose a POST endpoint of your own that validates input and returns JSON.

## Key concepts

- **HTTP methods and status codes**
- **Headers and authentication**
- **JSON and JSON Schema basics**
- **curl and API clients**
- **Timeouts, retries and backoff**
- **Server-Sent Events**: How token streaming works
- **FastAPI**
- **Express / Hono**

## Mini project

Build a FastAPI (or Express) service with one POST endpoint that validates a JSON body, calls a public API with a timeout and retries, and returns a clean JSON response or a meaningful error code.

## Check yourself

Which HTTP status codes should your client retry automatically, and which should it never retry? Why?

## Free resources

- [MDN: An overview of HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview) (MDN)
- [FastAPI tutorial](https://fastapi.tiangolo.com/tutorial/) (FastAPI)
- [MDN: Using server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) (MDN)

Previous: [Git and Project Hygiene](https://www.internhack.in/roadmaps/tracks/ai-engineer/git) · Next: [Async I/O and Concurrency](https://www.internhack.in/roadmaps/tracks/ai-engineer/async-programming)

## More in Engineering Foundations for AI Work

- [Python for AI Engineers](https://www.internhack.in/roadmaps/tracks/ai-engineer/python)
- [TypeScript for AI Engineers](https://www.internhack.in/roadmaps/tracks/ai-engineer/typescript)
- [Git and Project Hygiene](https://www.internhack.in/roadmaps/tracks/ai-engineer/git)
- [HTTP, REST APIs and JSON](https://www.internhack.in/roadmaps/tracks/ai-engineer/http-apis-json)
- [Async I/O and Concurrency](https://www.internhack.in/roadmaps/tracks/ai-engineer/async-programming)
- [SQL and Postgres Basics](https://www.internhack.in/roadmaps/tracks/ai-engineer/sql-basics)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
