A simple RESTful API built with Dart using the shelf framework, MySQL database, and YAML as the default format for both input and output — not JSON.
⚠️ This project demonstrates that YAML can be a modern alternative to JSON in API communication, offering better readability and structure for human developers.
This project implements a basic Contact Management System (CRUD) API with the following features:
- Accepts YAML-formatted requests
- Returns YAML-formatted responses
- Uses:
shelf: For lightweight HTTP servermysql_client: To connect to MySQLyaml: To parse YAML inputyaml_writer: To serialize objects into YAML
All endpoints return standardized YAML responses using the YamlHelper.generateResponse() utility.
While most APIs use JSON by default, this project chooses YAML over JSON for several reasons:
| Feature | Advantage |
|---|---|
| Human-readable formatting | Easier to read and write manually |
| Supports complex structures | Great for nested or hierarchical data |
| Widely used in DevOps | Aligns well with infrastructure-as-code workflows |
This makes it ideal for APIs consumed by both humans (e.g., CLI tools, documentation) and services.
- ✅ CRUD Contacts: Create, Read, Update, Delete
- ✅ Input Validation: Name, phone number, email, address
- ✅ Filtering: By name, email, phone number
- ✅ Sorting: By field (
name,email, etc.) - ✅ Standardized Responses: All outputs are returned in consistent YAML format
- ✅ Self-documented Code: Clear comments across all files
- ✅ Open Source (BSD License)
- Language: Dart
- HTTP Framework: Shelf
- Database: MySQL
- Data Formats:
- Request Body: YAML
- Response Body: YAML
- YAML Processing:
yaml,yaml_writer
git clone https://github.com/<your_username>/dart-yaml-api.git
cd dart-yaml-apidart pub getMake sure you have MySQL running and create the database:
CREATE DATABASE contacts_db;
USE contacts_db;
CREATE TABLE contacts (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
phone_number VARCHAR(20) NOT NULL,
email VARCHAR(255),
address TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);dart run bin/server.dartThe server will run at: http://localhost:8080/api/contacts
http://localhost:8080/api/contacts
Success response:
status_code: 200
message: Task John Doe created successfully
result:
name: John Doe
phone_number: "+628123456789"Error response:
status_code: 400
message: Validation failed
errors:
name: Must be at least 2 characters
phone_number: Invalid phone number format| Method | Path | Description |
|---|---|---|
| POST | /create |
Create new contact from YAML body |
| GET | / |
Get list of contacts (with filtering/sorting support) |
| GET | /{id} |
Get single contact by ID |
| PUT | /{id}/update |
Update contact by ID |
| DELETE | /{id}/delete |
Delete contact by ID |
name: John Doe
phone_number: "+628123456789"
email: john@example.com
address: Jakarta, Indonesiastatus_code: 200
message: Task John Doe created successfully
result:
name: John Doe
phone_number: "+628123456789"
email: john@example.com
address: Jakarta, Indonesiastatus_code: 400
message: Validation failed
errors:
name: Must be at least 2 characters
phone_number: Invalid phone number formatEach contact must meet the following requirements:
name: Minimum 2 charactersphone_number: Valid international phone number formatemail: If provided, must match standard email patternaddress: Optional, max 255 characters
If validation fails, the API returns:
status_code: 400
message: Validation failed
errors:
name: Must be at least 2 characters
phone_number: Invalid phone number formatThis project uses a Model-View-Controller (MVC) architecture:
| Folder | Contents |
|---|---|
lib/models/ |
Data models (Contact) |
lib/controllers/ |
Business logic and route handlers |
lib/routes/ |
Route definitions |
lib/helpers/ |
Utility classes (ValidationHelper, YamlHelper) |
bin/ |
Main server entry point |
This project is released under the BSD 2-Clause License – see the LICENSE file for details.
Contributions are welcome!
- Fork the repo
- Create a new branch:
git checkout -b feature/yaml-enhancement - Commit your changes:
git commit -m 'Add YAML-based endpoint' - Push to the branch:
git push origin feature/yaml-enhancement - Submit a pull request
For help or questions:
- Telegram: @da578
- LinkedIn: Dzulkifli Anwar
- GitHub Issues: Open an issue on the repository
Thank you for checking out this project! I hope it inspires more developers to consider YAML as a structured and readable alternative to JSON in future API designs.