Saloon SDK Implementation Guide
This guide documents the simplified architecture and patterns for implementing new SDKs using Saloon with raw JSON responses. 💡 Pro Tip for AI Agents: Always start by examining the closest existing implementation to your target API. For simple token-based APIs, study HubSpot. For complex OAuth APIs, study Business Central. For multi-credential APIs, study Harvest.Table of Contents
Architecture Overview
Our SDK architecture follows a consistent pattern across all services:Core Components
- Service Class: Main entry point using WithResources trait
- Resource Classes: Group related functionality (e.g., DealsResource, ItemsResource)
- Connector: Handles HTTP connection and authentication
- Request Classes: Define individual API endpoints
- Raw JSON: Direct API responses for maximum performance
- DataCollection: Collections using
collect($arrays)
Resources Pattern
Why Use Resources?
Resources organize related API methods into logical groups, preventing the main service class from becoming unwieldy.Before vs After
Resource Implementation
Step-by-Step Implementation
1. Create Configuration
config/{servicename}.php:
2. Create Connector
src/Services/{Service}/{Service}Connector.php:
3. Create Request Classes
src/Services/{Service}/Requests/Get{Resources}Request.php:
4. Create Resource Classes
src/Services/{Service}/Resources/{Resource}Resource.php:
5. Create WithResources Trait
src/Services/{Service}/WithResources.php:
6. Create Main Service Class
src/Services/{Service}/{Service}.php:
7. Create Temporary test command
Do this while developing to verify that your SDK actually works. Ask the user to configure the .env variables correctly so that you can hit the live API. After you’re done, delete the test command.app/Console/Commands/Tests/Test{Service}Command.php:
Templates
Directory Structure
BaseResource Class
Best Practices
Naming Conventions
- Service classes:
{ServiceName}(e.g.,HubSpot,BusinessCentral) - Connectors:
{ServiceName}Connector - Resources:
{Resource}Resource(e.g.,DealsResource,ItemsResource) - Requests:
{Action}{Resource}Request(e.g.,GetDealsRequest,CreateDealRequest)
Method Naming
- List multiple:
list()→ returnsDataCollection<array> - Get single:
get($id)→ returnsarray - Search:
search($filters)→ returnsDataCollection<array> - Manual pagination:
paginate()→ returnsOffsetPaginator
Performance Patterns
Error Handling
Configuration
Implementation Checklist
- Configuration: Create
config/{service}.php - Connector: Create connector with authentication
- Requests: Create request classes implementing
Paginatable - Resources: Create resource classes extending
BaseResource - WithResources: Create trait organizing resource accessors
- Service: Create main service class using
WithResources - BaseResource: Create base resource with connector injection
- Testing: Create test command
- Performance: Use
array_merge($items, $rawData)pattern - DataCollection: Use
collect($arrays)