@rewritetoday/types, an official TypeScript types for the Rewrite API.
This package provides shared resource models, request/response contracts, and route builders used by Rewrite SDKs and applications. It is designed to keep API integrations strongly typed and consistent across projects.
You can use this package with your favorite package manager
bun add @rewritetoday/types
# Or
npm install @rewritetoday/types
# Or
pnpm install @rewritetoday/types
# Or
yarn add @rewritetoday/typesPrefix
API*Represents general API structures (returned objects, internal models, etc.).Prefix
REST<HTTPMethod>*Types used in direct API requests.Suffix Body → request body payload E.g.:
RESTPostCreateTemplateBodySuffix
QueryParams→ query string parameters E.g.:RESTGetListWebhooksQueryParamsSuffix
Data→ data returned by the API E.g.:RESTGetListWebhooksData
Prefix
Webhook*Represents any data that come from a webhook.
import{REST}from'@rewritetoday/rest';import{Routes,typeRESTGetProjectData}from'@rewritetoday/types/v1';constrest=newREST(process.env.REWRITE_API_KEY);// Return type: Promise<RESTGetWebhooksData>asyncfunctionfetchHooks(){constdata=awaitrest.get<RESTGetWebhooksData>(Routes.webhooks.list());returndata}We are using Bun here as example, but you can use it however you want.
import{typeWebhookEvent,WebhookEventType}from'@rewritetoday/types/v1';constserver=Bun.serve({port: 3000,routes: {async'/webhooks/rewrite'(request){constevent: WebhookEvent=awaitrequest.json();switch(event.type){caseWebhookEventType.MessageSent:
console.log('Hey, a new message!');returnResponse.json({});case ...
}},},});import{API_VERSIONAPI_BASE_URL,Routes}from'@rewritetoday/types/v1';// https://api.rewritetoday.com/v1/templatesconstCREATE_TEMPLATE_URL=`${API_BASE_URL}/${API_VERSION}/${Routes.templates.create()}`;Made with 🤍 by the Rewrite team.
SMS the way it should be.