Skip to content
Index Ai Academy

Build and Operate HTTP APIs

Design, test, deploy, and operate an HTTP API that another engineer can use.

Already have an account? Sign in

First principles

How do two independent programs agree on a change to shared state?

A request carries an operation, its inputs, and a caller identity. The API validates the contract and caller before work starts, then returns a result a separate client can interpret or retry.

  1. Starting point

    A client sends CSV and an idempotency key with its authenticated request.

  2. What changes

    The API validates it and records one queued import for that caller and key.

  3. Result

    The worker completes the job and the client looks up the same report.

Compare all three steps
  1. Starting point

    A client sends CSV and an idempotency key with its authenticated request.

  2. What changes

    The API validates it and records one queued import for that caller and key.

  3. Result

    The worker completes the job and the client looks up the same report.

Complete and reverse the trace

Given A client sends CSV and an idempotency key with its authenticated request. and The worker completes the job and the client looks up the same report., write down the missing step that connects them.

Compare with the worked step

The API validates it and records one queued import for that caller and key.

Now take The API validates it and records one queued import for that caller and key. and the result above. Write an input and an implementation that could produce this trace.

Check one starting point

A client sends CSV and an idempotency key with its authenticated request.. Check that your implementation produces the result shown above.

Try it on a new case

The connection closes after the server commits the job. What should the client reuse on retry?

Show worked reasoning

Send the same body, caller identity, and idempotency key. The server can return the existing job. A different body with that same key should surface a conflict.

A retry crosses a worker failure

  1. First POST

    Account A sends key 42. The API records job J; the reply is lost.

  2. Retry

    Account A sends the same data and key 42.

  3. Another account

    Account B sends the same data and key 42.

How many job records should exist? What two things should the contract test assert for Account A?

Compare your reasoning

Two jobs should exist because the key belongs to each caller’s request scope. The retry from A returns a reference to J and never creates another A job. A can retrieve J without seeing B’s job.

Hand an import API to another client developer

Transport communicates intent and a result. The contract, caller scope, and durable operation identity determine whether a retry represents work already done.

  1. Start with a small case

    The first submit stores a job but its HTTP response is lost. Trace a retry with the same key and payload, then a later request with the same key and changed payload.

  2. Produce evidence

    Give a reviewer the OpenAPI contract, a running FastAPI service, and an independent TypeScript client. Show one job after the retry, a conflict for the changed payload, and a denied cross-caller read.

  3. Try a changed brief

    Deploy a backward-compatible field addition. Use the same client and a rollback rehearsal to show that both versions preserve the agreed behavior.

Plan your practice and handover
  1. Start with the first lesson . Check the prerequisites under Before you start.
  2. Write a prediction for the small case above and record the result. Keep the fixture and the steps someone else needs to reproduce it.
  3. Use the changed brief to solve a case independently. Show what you changed, the output or test that supports your decision, and one condition that would make it fail.
  4. Open the final lesson . Give a reader the artifact described above and ask them to reproduce one result from your notes.
Between lessons

Enforce the request contract at the service boundary

The import contract specifies an integer clicks count. Pass that contract into a function modeling the request-validation layer.

Run the starter, predict the changed result, and then edit and run it again.

Replace the string '12' with the integer 12. Check the client-visible status and the accepted value.

body = {"clicks": "12"}
value = body.get("clicks")
if type(value) is int:
    print(f"202 | clicks={value}")
else:
    print("422 | clicks must be an integer")
Compare against the expected output

Starter output

422 | clicks must be an integer

Changed output

202 | clicks=12
Common failure to check

Coercing strings makes malformed clients look healthy and hides a contract mismatch. Return a clear error unless the contract explicitly allows coercion.

Take the changed output into the next lesson and explain which part of the handoff the next lesson needs.

Choose how to practice

Begin with How APIs work. Each lesson offers these practice modes and a saved handoff.

Work on the campaign checker

Use the campaign import service to practice an API contract, SQL-backed jobs, safe retries, and access checks.

Project workshop

Build it and prove each change

Use the campaign service starter from Software Lab. Follow each stage, collect the evidence, then move to the independent brief.

  1. 1

    Read a request on the wire

    Submit the synthetic CSV as JSON. Record the request method, headers, body, response status, and Location. Follow Location as a separate client.Evidence to collect. Explain which fields belong to the transport and which belong to the import itself. Show the difference between a bad request and an accepted job still in progress.Open the lesson
  2. 2

    Publish a contract clients can test

    Write the expected inputs, output states, and common errors into your contract. Inspect the generated OpenAPI and connect the TypeScript caller using its documented shapes.Evidence to collect. Give a classmate only the contract and an API address. Have them read one job and explain an error from the response without reading the server code.Open the lesson
  3. 3

    Store one job per caller and operation

    Persist imports in SQLite and move processing to a worker. Make the caller and idempotency key unique together. Reject the same key with changed request content.Evidence to collect. Submit the same body twice, run the worker, and show both requests identify the same job. Repeat with a changed body to demonstrate the conflict.Open the lesson
  4. 4

    Separate authenticated roles and resources

    Give each practice caller distinct credentials. Apply report ownership to reads and check the analyst permission separately for note writes.Evidence to collect. Show an analyst reading their report and adding one note. Show a reviewer reading their own report and receiving a denial when attempting to write a note.Open the lesson
  5. 5

    Protect a downstream client during change

    Add an optional response field. Keep the existing job states and error shape stable while you exercise retries and timeouts with the same TypeScript client.Evidence to collect. Run the unchanged client against both revisions. Simulate a connection failure after submission and verify the retry returns the original job.Open the lesson
  6. 6

    Ship, observe, recover, and hand over

    Start the API and worker with the container starter. Stop the worker, inspect queue progress and health, restore processing, and rehearse a rollback to the recorded image.Evidence to collect. Have a reviewer follow your runbook from a fresh checkout. Capture a successful check, the incident timeline, and how they knew recovery was complete.Open the lesson
What you'll learn

What you'll be able to do.

HTTP, OpenAPI, FastAPI, SQL, authorization, retries, deployment, and rollback.

In order

The 20 lessons.

2 are free with no account, and a free account opens the rest.

  1. How APIs work FreeRequests, responses, methods, status codes and headers.30 min
  2. HTTP from the wire up FreeWhat really travels between client and server: bytes, headers and bodies.40 min
  3. API stylesREST, RPC, GraphQL, gRPC and streaming: what each is for.35 min
  4. Build an API server from scratchRouting, handlers and responses, with no framework.45 min
  5. A web framework, from the insideDecorators, middleware and error handling: how Flask and FastAPI work.40 min
  6. Designing a REST APIResources, methods, status codes, errors and pagination done well.45 min
  7. Validating requests with schemasCheck every request against a JSON Schema and say exactly what's wrong.45 min
  8. A database-backed APICRUD endpoints on SQLite, with safe concurrent updates.45 min
  9. Authentication and authorizationAPI keys, sessions, tokens and OAuth: who's calling, and what may they do?45 min
  10. Rate limits, retries and idempotencyKeep an API up under load and make retries safe.45 min
  11. Async HTTP clientsMany requests at once with asyncio and httpx: limits, timeouts and retries.45 min
  12. Webhooks and eventsPush events to other systems: signed, retried and deduplicated.45 min
  13. Documenting APIs with OpenAPIA machine-readable contract for docs, SDKs and AI tools.40 min
  14. APIs with FastAPITyped routes, pydantic models, automatic validation and docs, tested with httpx.45 min
  15. Project: a FastAPI service with accountsA session per request, bcrypt sign-ups, signed tokens, ownership checks and tests on a fresh database.45 min
  16. Modules, Node and reading TypeScriptimport and export, package.json, classes, and types as notes the compiler checks, read through a small tool server.30 min
  17. Running APIs in productionVersioning, CORS, caching, request ids and health checks.45 min
  18. CI/CD pipelinesTest every change automatically, and ship with gates, flags and rollbacks.40 min
  19. Metrics, dashboards and alert rulesCounters, gauges and histograms, a rate from a counter, a percentile from buckets, a dashboard panel and an alert rule that fires on a sustained condition.40 min
  20. Project: a reviews APIAn authenticated, validated, paginated API with tests.45 min
Before and after

Where it starts, and what you earn.

Before you start

Some lessons here build on earlier ones in the academy. The placement test can mark off what you already know, and you can open any of them first:

New to Python? Start with the free Python for AI course.

When you finish

Finish every lesson and get staff approval on “Deploy a support import and reporting API” in My projects to earn the course certificate. The course ends with its own checkpoint, 12 questions the academy's server draws and marks itself. Pass it to verify the certificate and count lessons you skipped in the placement test.

Questions

Before you sign up.

Is it really free?

Yes. There's nothing to pay, here or anywhere in the academy. A free account saves your progress and issues your certificate.

Do I need to install anything?

The lessons run in your browser. The downloadable service project uses a local Python environment.

How long does it take?

About 16.5 hours in all, at your own pace. Your progress stays where you left it.

What does the certificate show?

You completed the course and passed a staff-reviewed independent project, “Deploy a support import and reporting API”. See My projects for the brief, evidence requirements, and submission.

Keep learning

Other free courses.

Or take the whole course: 575 lessons, from your first line of Python to production AI.

32 lessons about 21.5 hours

Free Python for AI course

Learn Python from your first line of code to your first call to a language model, with nothing to install.

15 lessons about 9.5 hours

Free prompt engineering course

Learn to write prompts that work reliably, then test them like an engineer: clear instructions, examples, structured output, chains, evals and defenses against prompt injection.

14 lessons about 9 hours

Free RAG course

Build retrieval-augmented generation step by step: embeddings, chunking, vector search, grounded answers with sources, and the measurements that tell you whether it works.

29 lessons about 22.5 hours

Free AI agents course

Learn how to build AI agents by building one: tools, the agent loop, MCP, permissions, context management and evals, ending with a coding agent that stops when its tests pass.

22 lessons about 16 hours

Build an LLM from scratch: a free course

Go from counting letter pairs to a small GPT you train yourself: tokenizers, attention, transformer blocks and the GPT architecture, written line by line.

127 lessons about 101.5 hours

Free Python developer course

Go from your first line of code to working as a Python developer: projects, testing, data, databases, web apps and APIs, all in your browser.

5 lessons about 3.5 hours

How Transformers Think: an interactive inference walkthrough

Follow one prompt, "The cat sat", through a language model with every number shown: tokens to IDs, embeddings and positional waves, the attention matrix, the feed-forward layer, and the probability over the next word.

6 lessons about 3 hours

Why Models Do That: six behaviors, traced to the mechanism

Confident wrong answers, miscounted letters, copying from the prompt, temperature, long prompts that dilute, and a model that never says "I don't know": each behavior reproduced on a tiny GPT with every number printed by code, then the mechanism behind it and the Phase 1 technique it justifies.

17 lessons about 13.5 hours

Creating Custom LLMs: Editing Open Weights Using Weight-Space Programming

Read a model's weights, change them by hand and judge an edit someone else made: deltas, merging, low-rank edits, directions and fact edits on a tiny GPT in your browser. Then replay recorded sessions of an LLM reading, fixing and writing weights, check the published edit of a real open model, and ship a model of your own with its patch, verdict and card. Every number is printed by the lesson's own code, and the method's limits are taught with it.

11 lessons about 9 hours

Free MLOps course: running machine learning in production

Take a model from a notebook to a system that stays right: track and reproduce every run, search settings honestly, version data and models, promote through gates, keep training and serving in step, choose batch or online, catch drift, and retrain through a pipeline. Every number is measured by the lesson's own code.

118 lessons about 95.5 hours

The Foundation Math For Ai & ML: from arithmetic to attention

Learn the math behind AI from arithmetic up: numbers, algebra, vectors and matrices, calculus, probability and statistics, each shown as numbers moving and checked in Python, ending with a network you build and train from the formulas.

19 lessons about 15 hours

Transposition of Formulas: algebraic manipulation in every topic

Learn to make any letter of any formula the subject: layers undone in reverse order, fractions, a letter that appears twice, powers, roots, quadratics, logs, inequalities, trigonometry, vectors, matrices, calculus, probability, statistics and the formulas inside AI models, each checked in Python.

15 lessons about 11.5 hours

Build and Deploy MCP Integrations

Build a Model Context Protocol client and server, then verify the integration with a compatible host.

13 lessons about 11 hours

LLM Harness

Build a bounded run loop, test it with scripted model responses, and recover interrupted work from an event log.

Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write

Free, with a certificate

Start the course.

A free account saves your progress across devices and issues your certificate when you finish.