nodejs-http-client icon indicating copy to clipboard operation
nodejs-http-client copied to clipboard

This repo is no longer maintained. Please use https://github.com/sendgrid/sendgrid-nodejs/tree/HEAD/packages/client instead

This repo is no longer maintained. Please use https://github.com/sendgrid/sendgrid-nodejs/tree/HEAD/packages/client instead.

SendGrid Logo

Build Status Email Notifications Badge npm version Twitter Follow GitHub contributors MIT license

Quickly and easily access any RESTful or RESTful-like API.

If you are looking for the SendGrid API client library, please see this repo.

Announcements

All updates to this library are documented in our CHANGELOG.

Table of Contents

  • Installation
  • Quick Start
  • Usage
  • Roadmap
  • How to Contribute
  • About
  • License

Installation

Prerequisites

  • Node.js version 0.10, 0.12 or 4

You need to have a API key to use the app. To configure the API key in the environment variables follow these steps.

  • create .env file in the root directory of the project.
  • Copy the contents of .env_sample file in to the .env file
  • Once you have obtained the API key, find the environment variable SENDGRID_API_KEY and assign your API key as it's value. As an example it should look like this
SENDGRID_API_KEY='<YOUR_API_KEY>';

Install Package

npm install sendgrid-rest

Quick Start

GET /your/api/{param}/call

var Client = require('sendgrid-rest').Client
var client = new Client()
var request = client.emptyRequest()
var param = 'myparam'
request.host = 'api.example.com'
request.method = 'GET'
request.path = '/your/api/' + param + '/call'
client.API(request, function (response) {
  console.log(response.statusCode)
  console.log(response.body)
  console.log(response.headers)
})

POST /your/api/{param}/call with headers, query parameters and a request body.

var Client = require('sendgrid-rest').Client
var client = new Client()
var request = client.emptyRequest()
request.host = 'api.example.com'
request.headers['Authorization'] = 'Bearer XXXXXX'
request.queryParams['limit'] = 100
request.queryParams['offset'] = 0
request.method = 'POST'
var param = 'myparam'
request.path = '/your/api/' + param + '/call'
requestBody = {
  'some': 0,
  'awesome': 1,
  'data': 3
}
request.body = requestBody
client.API(request, function (response) {
  console.log(response.statusCode)
  console.log(response.body)
  console.log(response.headers)
})

Usage

Following is an example using SendGrid. You can get your free account here.

First, update your environment with your SENDGRID_API_KEY.

You can copy the .env_example file located in the "examples" folder to .env in your project's root.

cp examples/.env_sample .env

Once you have edited the file and added your API Key, you can add the variable to your environment: source .env

Here is the full working code.

To run the example:

node examples/example

======= Library Usage Documentation

Tests

Tests can be run through a Docker container which is defined in the docker-compose.yml file.

To run the tests, simply run docker-compose up.

Roadmap

If you are interested in the future direction of this project, please take a look at our milestones. We would love to hear your feedback.

How to Contribute

We encourage contribution to our libraries, please see our CONTRIBUTING guide for details.

About

nodejs-http-client is maintained and funded by Twilio SendGrid, Inc. The names and logos for nodejs-http-client are trademarks of Twilio SendGrid, Inc.

If you need help installing or using the library, please check the Twilio SendGrid Support Help Center.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

License

The MIT License (MIT)