Type-safe wrappers for third-party REST APIs.
Supports Twilio, Postmark, and more. Show all
// before - nothing is typed
await fetch('https://api.postmarkapp.com/email', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Postmark-Server-Token': 'secret',
},
body: JSON.stringify(body),
});
// after - fully typed request and response
await sendEmail(body, { serverToken: 'secret', from: '[email protected]' });- Type Safety: Fully typed request and response bodies
- Zero Overhead: Primarily types with minimal runtime code
- Easy Migration: Uses each API's native request body format
- Explicit Errors: Type-safe responses without
try...catch - Fetch API: Built on the Fetch API with override support
npm install new-requestAll modules follow a consistent pattern:
const response = await moduleName(requestBody, options);
// Failures are returned, not thrown
if (response instanceof Error) return; // network error, etc.
// Response types are automatically narrowed
if (response.ok) response; // success type
if (!response.ok) response; // error typeSending an email with the Postmark API:
import { sendEmail, type Options } from 'new-request/email/postmark/POST';
// Options can be modularized and exported
const options: Options = {
serverToken: 'your_server_token_here',
from: '[email protected]',
};
const response = await sendEmail(
{
// Request body matches the Postmark API for easy migration
// https://postmarkapp.com/developer/api/email-api
To: '[email protected]',
Subject: 'Hello World',
TextBody: 'Email body',
From: '[email protected]', // optional override
},
options,
);
if (response instanceof Error) {
// Network error, unparsable body, etc.
console.error('Request failed:', response.message);
return;
}
if (!response.ok) {
response.status; // 401 | 404 | 413 | 415 | 422 | 429 | 500 | 503
response.body.ErrorCode; // Postmark error code
return;
}
response.body.MessageID; // 200 OKNote
나이스 교육정보 개방 포털 학교기본정보 was removed. Use neis-school-info instead.
import { sendEmail } from 'new-request/email/postmark/POST';- Pushover
- 비즈고 (문자, RCS, 카카오 비즈메시지, 네이버 톡톡)
- NHN Dooray! 두레이 메신저 웹 훅
import { sendMessage } from 'new-request/message/bizgo/v1/send/omni/POST';
import { sendMessage } from 'new-request/message/dooray/POST';
import { pushMessage } from 'new-request/message/pushover/1/POST';import { sendSms } from 'new-request/sms/nhn/v3.0/POST';
import { sendSms } from 'new-request/sms/twilio/2010-04-01/POST';import { textToSpeech } from 'new-request/tts/naver/v1/POST';