Generic Node.js REST Client

2.6.1 · abandoned · verified Wed Apr 22

sendgrid-rest is a lightweight, generalized HTTP REST client library designed for Node.js environments. It provides a simplified, callback-based interface for making HTTP requests to any RESTful or RESTful-like API, abstracting away some of Node.js's native `http`/`https` module complexities. The package is currently at version 2.6.1, with the last release dating back to March 2020. Releases have been infrequent and focused on maintenance, documentation, and minor dependency updates (TypeScript type definitions were added in v2.6.0). This library is explicitly *not* the official SendGrid API client; for SendGrid-specific interactions, users are directed to the `@sendgrid/client` package. Its core design uses traditional CommonJS modules and callback patterns, reflecting its age, and it officially supported very old Node.js versions (0.10, 0.12, 4).

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to make a POST request to a hypothetical REST API, including setting headers, query parameters, and a JSON request body using the callback-based API.

const Client = require('sendgrid-rest').Client;
const client = new Client();
const request = client.emptyRequest();
const param = 'myparam';

request.host = 'api.example.com';
request.headers['Authorization'] = 'Bearer XXXXXX'; // Replace XXXXXX with your actual token
request.queryParams['limit'] = 100;
request.queryParams['offset'] = 0;
request.method = 'POST';
request.path = '/your/api/' + param + '/call';

const requestBody = {
  'some': 0,
  'awesome': 1,
  'data': 3
};
request.body = requestBody;

client.API(request, function (response) {
  console.log('Status Code:', response.statusCode);
  console.log('Response Body:', response.body);
  console.log('Response Headers:', response.headers);

  if (response.statusCode >= 400) {
    console.error('API Error:', response.body);
  }
});

view raw JSON →