PES Guide

Backend

Keep the frontend moving while the backend is not there yet

Agree on the API contract on day one, build against a fake API (a mock) and, once the backend is ready, change a single line. Use the hosted Mock API, with PES examples, and deploy on virtech when the time comes.

Three ways to mock an API

They are not exclusive: teams often start with the first and move to the second when the frontend needs a real server.

No server

Fake data source

A Fake implementation of the interface the app uses. The fastest way to start the UI, and what your unit tests use.

Real REST

json-server

A full API from a db.json: GET, POST, PUT, PATCH and DELETE, filters, pagination and relations. Changes are saved to the file. Works for the whole team and for phones.

Contract first

Prism + OpenAPI

A mock that answers according to the contract and validates requests. Ideal for services between teams: the OpenAPI file is the agreement between both.

A real mock API, one click away

The Mock API gives you an HTTPS URL with full CRUD that the emulator, phones and the whole team can call without installing anything. It also writes the Kotlin and Dart code, the OpenAPI file and the db.json for json-server, and you can export the project to carry on next sprint.

From the mock to the real backend, changing one line

The key is that the UI does not know where the data comes from. It depends on an interface and, at start-up, the app decides which implementation to plug in.

UICompose · widgets
events
ViewModel · BLoClogic
call
StationsDataSourceinterface
FakeStationsDataSourcesprint 1 · tests
HttpStationsDataSourcejson-server · virtech · real API
// build.gradle.kts: buildConfigField("boolean", "USE_MOCK", "true") in the debug build
val dataModule = module {
    single<StationsDataSource> {
        if (BuildConfig.USE_MOCK) FakeStationsDataSource()
        else HttpStationsDataSource(baseUrl = "http://10.0.2.2:8080/")
    }
    viewModel { StationsViewModel(get()) }
}
Which address? From the Android emulator, your computer's localhost is 10.0.2.2. The iOS simulator uses localhost. A real phone on the same Wi-Fi uses your computer's local IP (hence --host 0.0.0.0). Away from home, virtech.

Deploying on virtech

Type your machine's IP and the kind of backend (mock, Node, Spring Boot, Django or Flask, Docker) and get every command: NAT ports, SSH, a systemd service, the outside test and the app settings for HTTP.

Open the virtech guide