Agentic AI · Intermediate level

Intermediate level · Module 4: External API Integration · Lesson 1 of 3

A Local Mock API for Practice

Learners build a small FastAPI service with fictional data (for example market prices or programme timetables) so that API-calling agents can be developed offline and safely.

In this lesson you will

  • Build a read-only mock API with FastAPI
  • Document the API's endpoints

Key concepts

FastAPIGET endpointsJSON responsesfictional dataAPI documentation

The lesson

Real APIs may need internet, keys and payment, and may change. A local mock API with the same shape lets learners develop and test agents offline. FastAPI creates one in a few lines and generates interactive documentation automatically.

The mock serves fictional data, for example weekly prices of maize and sorghum at three fictional markets, through read-only GET endpoints such as /prices?crop=maize&market=Market%20A.

Design the mock to include failures on purpose (a slow endpoint, an occasional error), so that the agent's error handling can be tested.

Step by step

  1. Create a FastAPI app with two GET endpoints and fictional data.
  2. Run it locally with uvicorn and open its documentation page.
  3. Add a deliberately slow endpoint and a random error.
  4. Write the endpoint descriptions for the agent's tool.

Practice activity

Build the project's read-only mock data API.

Expected result: A running mock API with documented endpoints and deliberate failure modes.

Check your understanding

  1. Why use a mock API during development?

    Show answer

    It works offline, costs nothing, and its behaviour, including failures, can be controlled.

  2. Which HTTP method should read-only endpoints use?

    Show answer

    GET.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.