Skip to content
/ apidog Public

A simple project for a tech talk demo using ApiDog for mock API

License

Notifications You must be signed in to change notification settings

Jhoscy/apidog

Repository files navigation

🐶 ApiDog Flutter Demo

ApiDog Flutter Demo is a sample Flutter app built using Clean Architecture principles to demonstrate how to consume a REST API using ApiDog in a modular, reusable, and scalable way.

⚙️ Built with Provider, flutter_dotenv, and a layered architecture: core, domain, data, and presentation.


🚀 Features

  • ✅ Fetch a single Pet
  • ✅ Fetch a list of Pets
  • ✅ Environment management via .env files
  • ✅ Proper separation of concerns through Clean Architecture
  • ✅ Centralized error handling using Failure and Exception classes
  • ✅ Generic API response handling with ApiResponse<T>

📁 Project Structure

lib/
├── core/
│   └── error/              → Error and exception handling
├── data/
│   ├── datasources/        → API services (http requests)
│   └── repositories/       → Repository implementations
├── domain/
│   ├── entities/           → Models and generic API responses
│   ├── repositories/       → Abstract repository interfaces
│   └── usecases/           → Reusable business logic
├── presentation/
│   ├── providers/          → State management
│   └── screens/            → UI layer (main screen)
└── main.dart               → App entry point and config

🌐 Environment Configuration with flutter_dotenv

This project uses flutter_dotenv to manage multiple environments such as development, staging, and production.

1. 📁 Create an environment/ folder in the root of your project

your_project/
└── environment/
    ├── .env.dev
    ├── .env.local
    └── .env.prod

2. ✏️ Add the API_URL variable to each .env file

Example .env.dev:

API_URL=https://dev.api.apidog.com

Example .env.prod:

API_URL=https://api.apidog.com

3. ⚙️ Load the env file in main.dart

By default, main.dart loads the .env.local file:

await dotenv.load(fileName: 'environment/.env.local');
final apiUrl = dotenv.env['API_URL']!;

💡 You can change which .env file to load based on the environment or flavor you want to run.

4. 🗂 Use Static JSON for Local Testing (Optional)

If you want to mock API responses using local static JSON files, such as:

  • assets/mock/pet_response.json → for a single pet detail
  • assets/mock/pet_list_response.json → for the list of pets

you can toggle this behavior using a JSON_DATA variable in your .env files.

ℹ️ Behavior based on JSON_DATA value

  • When JSON_DATA=true, the app will load data from local static JSON files instead of making real API calls.
  • When JSON_DATA=false, the app will use the live API defined in the API_URL variable.

5. 🔁 Standalone Detail Fetching via standalone Flag

In the pet_item.dart file, each PetItem can be configured with a standalone boolean flag:

  • When standalone = true, the Pet Detail page will fetch data directly from ApiDog using the pet ID.
  • When standalone = false, the Pet Detail page will receive the full Pet object via props, and no extra fetch is performed.

✅ This allows you to decide if the pet should be fetched or passed via widget prop.

Example:

# .env.local, .env.dev, or .env.prod
JSON_DATA=false
API_URL=http://127.0.0.1:3658/<apidog_path>
---
## 🧪 How to Run

### ✅ Start the app

1. Make sure your `.env` files are created inside the `environment/` folder
2. Make sure to have API_URL variable from apidog 
3. Make sure to have JSON_DATA variable setted to false/true
4. Run the app:

```bash
flutter pub get
flutter run

or for vs_code like, launch.json

{
    "version": "1.0.0",
    "configurations": [
        {
            "name": "Local",
            "request": "launch",
            "type": "dart",
            "program": "lib/main.dart",
            "args": [
                "--dart-define=ENV=local"
            ]
        },
    ]
}

💡 Extensibility

You can easily extend this project by adding more models and endpoints:

  • Create a new Entity class
  • Add a new Service and RepositoryImpl
  • Inject a new FetchApiData<T> use case into your Provider

📷 Screenshots

Home Screen Detail
home detail

📦 Main Dependencies


🤝 Contributing

Have an idea or a bug fix? Feel free to open a pull request! ❤️


📄 License

MIT License © 2025 Gionata Stante / Open Reply

About

A simple project for a tech talk demo using ApiDog for mock API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published