MODULES / 04 · DART & FLUTTER

HTTP APIs and asynchronous state

Prerequisites

Modules 1 through 3, Future and async/await.

Learning objectives

Consume external data, parse JSON at the boundary and distinguish loading, empty, success and error states.

Suggested activity

Choose a query and implement a reproducible error response. Use a replaceable client in tests so they do not depend on an external network.

The current application implementation determines the API and libraries in use. An old article title does not establish that DIO or Google Sheets remains the active integration. Use the current version of the chosen repository, synthetic data and its documented validation steps. Record the environment and distinguish real execution, emulation and a local demonstration. These activities are proposals for your own study repository.

Suggested reading

A Agência Holística de Depuração: use the reading as a starting point for investigating integration failures.

Agência Holística · Volume II — Tudo Tem Memória: Use the reading to investigate an integration failure with logs and a reproducible sequence.

Agência Holística · Volume III — A Conta Que Ficou: Discuss retries and idempotency: a test with a simulated client should check whether a retry duplicates an effect.

Books & sites

Case studies and references

Labs for this module

These activities connect each laboratory to the lesson. Integration suggestions are adaptations for your own project.

Apply in your course project

ML Engine

In the HTTP case study, transform a synthetic JSON response into validated numeric rows before passing them to a package estimator.

What to check: Test a valid response, a missing field and a nonnumeric value with a replaceable client; failure must be reported before training.

Apply in your course project

Decision Engine

Use a test HTTP source to load alternatives for a scenario. Convert data at the boundary and run the ranking only after loading.

What to check: Demonstrate loading, failure and success without making the decision rule depend on the HTTP client.

Explore the laboratories

05 / EXERCISES

Exercises

  1. 01

    States

    Objective: Represent loading, an empty response and a result.

    Completion criteria: Demonstrate each state with controlled data.

  2. 02

    Parsing

    Objective: Validate an unexpected response.

    Completion criteria: Handle invalid JSON or a missing field as a controlled error.

  3. 03

    Failures

    Objective: Handle a timeout or an unavailable service.

    Completion criteria: Show a message and allow another attempt without inventing successful data.

  4. 04

    Concurrency

    Objective: Prevent an old result from replacing the latest query.

    Completion criteria: Provide a test that controls the order of two responses.

  5. 05

    A contract

    Objective: Document a query.

    Completion criteria: Describe its input, output and limits, and run tests with synthetic fixtures.