Skip to content

RewriteToday/node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Rewrite Node SDK

rewritetoday, the official Node.js/TypeScript SDK for the Rewrite API.

It wraps authentication, typed REST calls, and resource helpers on top of @rewritetoday/rest and @rewritetoday/types.

Rewrite Banner

Installation

Use your preferred package manager:

bun add rewritetoday
# Or
npm install rewritetoday
# Or
pnpm add rewritetoday

Setup

First, you need to create an API key in the Rewrite Dashboard and use it in the constructor.

import { Rewrite } from 'rewritetoday';

const rewrite = new Rewrite(process.env.REWRITE_API_KEY);

Create the client

You can pass the API key directly or use the full options object.

import { Rewrite } from 'rewritetoday';

const rewrite = new Rewrite({
	secret: process.env.REWRITE_API_KEY,
	rest: {
		timeout: 10_000,
		headers: {
			'User-Agent': 'GetMonitor API (1.0.0)',
		},
	},
});

Send your first message

const { data, error } = await rewrite.messages.send({
	to: '+551234567890',
	content: 'Hey, Rewrite is here!',
});

You can view in our documentation everything in you can use when sending a message.

Error Handling

Requests run through @rewritetoday/rest. HTTP failures can throw HTTPError.

import { HTTPError } from '@rewritetoday/rest';

try {
	await rewrite.messages.get('invalid_id');
} catch (error) {
	if (error instanceof HTTPError) {
		console.error('HTTP Error:', error.status, error.method, error.url);
	}
}

Made with 🤍 by the Rewrite team.
SMS the way it should be.