Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-rest-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-rest-client

Simple HTTP wrapper for creating REST applications

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

simple-rest-client

This is a rest client that works for node.js v0.4.8 and up. It's a fairly straightforward wrapper; for something complicated, the http configuration can be easily manipulated.

Usage

Just instantiate a new client and configure it:

var REST = require('simple-rest-client');
var client = new REST.SimpleRestClient();

var config = {
	
	host: 'my.url.net',
	version: '/v1.0',
	port: '80',
	username: 'username',
	password: 'password',
	contentType: 'application/x-www-form-urlencoded'
	
};

client.setOptions(config);

Add url segments, and GET or POST parameters to the request (pass in null if there aren't any):

GET Requests

var segments = [];
		
	segments.push('foo');
	segments.push('bar');

var getParams = {};

	getParams['key'] = 'value';	
			
client.get(segments, getParams, function (response) {
	client.showResponse(response);
});

POST Requests

var segments = [];
		
	segments.push('foo');
	segments.push('bar');

var getParams = {};

	getParams['key'] = 'value';	
	
var postParams = {};

	postParams['key'] = 'value';	
			
client.post(segments, getParams, postParams, function (response) {
	client.showResponse(response);
});	

To POST to the body:

postParams['body'] = 'value';


DELETE Requests

var segments = [];
		
	segments.push('foo');
	segments.push('bar');

var getParams = {};

	getParams['key'] = 'value';	
	
var postParams = {};

	postParams['key'] = 'value';	
			
client.del(segments, getParams, postParams, function (response) {
	client.showResponse(response);
});

Keywords

FAQs

Package last updated on 22 Jan 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc