Enumerations
Relevant source files
The following files were used as context for generating this wiki page:
Enumerations in the Resend PHP library provide a structured way to define constant values used for HTTP communication. They ensure type safety and consistency across the transporter layer by restricting available options for HTTP methods and content types.
These enums primarily support the Transporter logic, which handles the underlying API requests to Resend services.
Architecture and Core Enums
The library organizes enumerations within the Resend\Enums\Transporter namespace. These enums are backed by strings, allowing them to be used directly in HTTP headers and request configurations.
ContentType
The ContentType enumeration defines the media types supported by the Resend API. It dictates how the request body is formatted and how the Content-Type header is set in outgoing requests.
| Case | Value | Description |
|---|---|---|
JSON | application/json | Standard format for most API interactions, such as sending emails or managing resources. |
MULTIPART | multipart/form-data | Used for file uploads, such as contact imports. |
Sources: src/Enums/Transporter/ContentType.php:5-9, tests/ValueObjects/Transporter/Payload.php:143-145
Method
The Method enumeration represents the standard HTTP verbs required to interact with RESTful resources. The Payload object uses these values to determine the action performed on the API endpoint.
| Case | Value | Usage Example |
|---|---|---|
GET | GET | Retrieving a list of API keys or a specific domain. |
POST | POST | Creating a new email, topic, or webhook. |
PATCH | PATCH | Updating existing resources like segments or contact properties. |
PUT | PUT | Replacing resource collections, such as thread labels. |
DELETE | DELETE | Removing a domain, api-key, or automation. |
Sources: src/Enums/Transporter/Method.php:5-12, tests/ValueObjects/Transporter/Payload.php:16-18, tests/ValueObjects/Transporter/Payload.php:37-39
Data Flow and Enum Integration
The following diagram illustrates how enums integrate into the request preparation process.
The diagram shows the relationship between transport value objects and the enums that define their behavior. Sources: tests/ValueObjects/Transporter/Payload.php:12-16, tests/Transporters/HttpTransporter.php:32-35
Interaction with Headers
The Headers value object provides a fluent interface to apply the ContentType enum. When you call withContentType(), the library maps the enum's backed string value to the Content-Type HTTP header.
$headers = Headers::withAuthorization(ApiKey::from('foo'))
->withContentType(ContentType::JSON);
// Results in: 'Content-Type' => 'application/json'
Sources: tests/ValueObjects/Transporter/Headers.php:14-22
Interaction with Payload and Requests
The Payload object creates a PSR-7 compliant request by combining a path, parameters, and the necessary transporter enums. The HTTP method is determined by the factory method used to create the payload (e.g., Payload::create() defaults to POST, while Payload::list() uses GET).
- POST/PUT Requests: Use
ContentType::JSONorContentType::MULTIPARTto encode the body. - GET/DELETE Requests: Typically do not include a body, so the content type is often omitted or defaults to JSON for consistency in headers.
Sources: tests/ValueObjects/Transporter/Payload.php:12-18, tests/ValueObjects/Transporter/Payload.php:48-50, tests/ValueObjects/Transporter/Payload.php:143-155
Implementation in HttpTransporter
The HttpTransporter class consumes these enums during its initialization and request execution phases. It uses the Headers object (which contains the ContentType) to ensure every request sent via the PSR-11 client has the correct metadata.
This class diagram represents the structural dependency of the transport layer on these enumerations. Sources: src/Enums/Transporter/ContentType.php:5-9, src/Enums/Transporter/Method.php:5-12, tests/Transporters/HttpTransporter.php:28-35
Conclusion
Enumerations in the Resend PHP SDK serve as the backbone for HTTP protocol compliance. By centralizing Method and ContentType definitions, the library prevents string-based errors and provides a clear contract for the HttpTransporter to interact with the Resend API.