sendgrid-kit

2.0.2

vapor-community/sendgrid-kit

What's New

2.0.2

2023-06-26T13:30:09Z

What's Changed

New Contributors

Full Changelog: 2.0.1...2.0.2

SendGridKit

Swift

SendGridKit is a Swift package used to communicate with the SendGrid API for Server Side Swift Apps.

Setup

Add the dependency to Package.swift:

dependencies: [
	...
	.package(url: "https://github.com/vapor-community/sendgrid-kit.git", from: "2.0.0")
],
targets: [
    .target(name: "App", dependencies: [
        .product(name: "SendGridKit", package: "sendgrid-kit"),
    ]),

Register the config and the provider.

let httpClient = HTTPClient(...)
let sendGridClient = SendGridClient(httpClient: httpClient, apiKey: "YOUR_API_KEY")

Using the API

You can use all of the available parameters here to build your SendGridEmail Usage in a route closure would be as followed:

import SendGridKit

let email = SendGridEmail(...)
try await sendGridClient.send(email)

Error handling

If the request to the API failed for any reason a SendGridError is thrown and has an errors property that contains an array of errors returned by the API. Simply ensure you catch errors thrown like any other throwing function

do {
    try await sendGridClient.send(...)
}
catch let error as SendGridError {
    print(error)
}

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Sun Apr 14 2024 22:32:02 GMT-0900 (Hawaii-Aleutian Daylight Time)