Giter Club home page Giter Club logo

auth-request's Introduction

auth-request

Node request util that supports request with basic or digest authentication.

Installation

$ npm install auth-request

Features

  • Support normal request, basic auth request, and digest auth request.
  • Support both http and https

Quick Start

var request = require('auth-request');
var options = {
	scheme: 'http',
	hostname: 'localhost',
	port: 8080,
	path: '/path/to/resource',
	method: 'POST',
	data: { message: 'hello world' },
	username: 'leo',
	password: 'xxx'
};
request(options, function (err, result) {
	if (err) return console.log(err);
	console.log(result);
});

API

var request = require('auth-request');

request(options, callback)

This is the main function used to make http request, accepts an option and a callback.

options

A json object that may contain following fields.

scheme

URL resource scheme, support http or https, defaults to http.

hostname

Request host, defaults to 'localhost'.

port

Request port, defaults to 80 when http, or 443 when https.

path

Request path, defaults to '/'.

method

Request method, defaults to 'GET'.

headers

Custom headers, optional, which will be appended to request headers.

data

Request data, if provided, data will be JSON-stringified to the request body, and content type will be set to 'application/json'.

username

Basic auth or digest auth username

password

Basic auth or digest auth password

callback(err, result)

Request callback function, called with error and result. The result object is of this structure { status: 200, data: ... }.

Test

There is a test server which you can use to test the correctness of an auth implementation.

TODO

  • Support digest auth with full coverage.
  • Refine code structure to support extension.
  • Refine test cases.

auth-request's People

Contributors

devxleo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.