A Dart package for interacting with YApi server APIs. This package provides easy-to-use methods to fetch interface and project data from YApi with proper authentication and error handling.
YApi is a powerful API management platform that allows teams to design, document, and test APIs collaboratively. This package simplifies the integration with YApi servers in Dart and Flutter applications.
- π Simple API Integration: Easy-to-use singleton pattern for YApi server communication
- π Authentication Support: Cookie-based authentication for secure API access
- π Interface Management: Fetch detailed interface/endpoint information including:
- Request/response specifications
- Headers, query parameters, and path parameters
- Request body configurations (JSON, form-data)
- Documentation and examples
- ποΈ Project Management: Retrieve comprehensive project data including:
- Project settings and configurations
- Environment configurations (dev, staging, production)
- Interface categories and tags
- Team members and roles
- π‘οΈ Error Handling: Robust error handling with proper logging
- π― Type Safety: Fully typed models with null safety support
- β‘ Performance: Efficient JSON parsing with safe type casting
- Dart SDK 3.6.2 or higher
- Access to a YApi server instance
- Valid authentication cookie for the YApi server
Add this package to your pubspec.yaml
:
dependencies:
yapi_api: ^1.0.0
Then run:
dart pub get
First, configure the YApi API helper with your server details:
import 'package:yapi_api/yapi_api.dart';
void main() async {
// Get the singleton instance
final yapiApi = YapiApiHelper();
// Configure your YApi server
yapiApi.baseUrl = 'https://your-yapi-server.com';
yapiApi.cookie = 'your-authentication-cookie';
}
Retrieve detailed information about a specific API interface:
// Fetch interface by ID
final interfaceResponse = await yapiApi.getInterface(12345);
if (interfaceResponse != null && interfaceResponse.errcode == 0) {
final interface = interfaceResponse.data!;
print('Interface: ${interface.title}');
print('Method: ${interface.method}');
print('Path: ${interface.path}');
print('Description: ${interface.desc}');
// Access request headers
if (interface.reqHeaders != null) {
for (final header in interface.reqHeaders!) {
print('Header: ${header.name} = ${header.value}');
}
}
// Access query parameters
if (interface.reqQuery != null) {
for (final param in interface.reqQuery!) {
print('Query: ${param.name} (${param.type})');
}
}
} else {
print('Failed to fetch interface: ${interfaceResponse?.errmsg}');
}
Get comprehensive project information including environments and team members:
// Fetch project by ID
final projectResponse = await yapiApi.getProject(67890);
if (projectResponse != null && projectResponse.errcode == 0) {
final project = projectResponse.data!;
print('Project: ${project.name}');
print('Base Path: ${project.basepath}');
print('Type: ${project.projectType}');
// Access environments
if (project.env != null) {
for (final env in project.env!) {
print('Environment: ${env.name} - ${env.domain}');
}
}
// Access categories
if (project.cat != null) {
for (final category in project.cat!) {
print('Category: ${category.name} - ${category.desc}');
}
}
// Access team members
if (project.members != null) {
for (final member in project.members!) {
print('Member: ${member.uid} (${member.role})');
}
}
} else {
print('Failed to fetch project: ${projectResponse?.errmsg}');
}
The package includes built-in error handling:
try {
final response = await yapiApi.getInterface(12345);
if (response == null) {
print('Network error or invalid response');
return;
}
if (response.errcode != 0) {
print('API Error: ${response.errmsg}');
return;
}
// Success - use response.data
final interface = response.data!;
// ... process interface data
} catch (e) {
print('Exception occurred: $e');
}
The main class for interacting with YApi servers.
baseUrl
: YApi server base URL (e.g., 'https://yapi.example.com')cookie
: Authentication cookie string
getInterface(int id)
: Fetches interface data by IDgetProject(int id)
: Fetches project data by ID
YapiInterfaceResponse
: Contains interface data with error handlingYapiProjectResponse
: Contains project data with error handlingYapiInterface
: Detailed interface/endpoint informationYapiProject
: Comprehensive project configuration and metadata
YApi (Yet Another API) is an open-source API management platform that helps teams:
- Design and document APIs collaboratively
- Generate API documentation automatically
- Test APIs with built-in tools
- Manage different environments (development, staging, production)
- Control access with user roles and permissions
We welcome contributions! Please feel free to submit issues and pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- π Bug Reports: GitHub Issues
- π‘ Feature Requests: GitHub Issues
- π Documentation: Check out the inline documentation in the source code
- π¬ Questions: Feel free to open a discussion in the repository
See CHANGELOG.md for a detailed history of changes.
This project is part of the FlutterCandies organization.
If you're working with APIs in Flutter, you might also be interested in:
http
: HTTP client for Dart (used internally by this package)dio
: Powerful HTTP client with interceptors and global configurationjson_annotation
: Code generation for JSON serialization
Made with β€οΈ by the FlutterCandies team