Prerequisites
- A Nuxt 3 or Nuxt 4 project
- Node.js 18 or later
- Authorize your sending domain
- Create or retrieve your SendLayer API key
Installation
Install the SDK in your project root.Storing your API key
Nuxt reads private values throughruntimeConfig. Declare the key at the top level of the config object so it stays on the server.
nuxt.config.ts
.env. Nuxt maps NUXT_SENDLAYER_API_KEY onto runtimeConfig.sendlayerApiKey automatically.
.env
Sending an email from a server route
Create a server route inserver/api/send-email.post.js. The .post suffix restricts the handler to POST requests.
server/api/send-email.post.js
readBody() parses the incoming JSON payload, and useRuntimeConfig(event) reads the private key at request time.
Use a
from address on a domain you authorized in SendLayer. Requests from an unauthorized domain fail.Reusing the client across routes
Create the client once in a server utility. Nitro auto-imports anything underserver/utils, so the helper is available in every route without an import statement.
server/utils/sendlayer.js
server/api/welcome.post.js
Calling the route from a Vue page
Use$fetch to post the form data. Nuxt sets the JSON content type when the body is an object.
pages/contact.vue
Testing the route
Start the development development server.Next Steps
Node.js SDK Reference
Review every method and parameter in the Node.js SDK.
Managing Webhooks
Track opens, clicks, and bounces with webhooks.
Retrieving Events
Query delivery events for any message.
Rate Limits
Understand recipient and request limits.