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

tiny_request

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny_request

Tiny module for networking

  • 1.0.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
232
decreased by-11.45%
Maintainers
1
Weekly downloads
 
Created
Source

Tiny module for http requests with no dependencies

Install

npm install tiny_request

Simple to use

var req = require('tiny_request')

req.get('http://google.com', function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) 
	} 
})

Examples

  • JSON
  • GET
  • POST Multipart
  • POST Froms
  • Custom HTTP Headers
  • Stream
  • Timeout

JSON

To automatically parse JSON you just need to pass JSON parameter.

Example:

req.get({ url: 'http://test.com/json', json: true}, function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) //body now is parsed JSON object
	} 
})

GET

req.get({ url: 'http://test.com', query: { test: 'test' }}, function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) 
	} 
})

Where query is GET parameters object

Also you can pass port parameter, for example:

req.get({ url: 'http://test.com', port: 8080}, function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) 
	} 
})

POST Multipart

var data = {
	image: {
		value: fs.createReadStream('photo.png'), 
		filename: 'photo.png',
		contentType: 'image/png'			
	},
	test: 'test'
}

req.post({
	url: 'http://test.com',
	query: { test: 'test' },
 	multipart: data 
}, function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) 
	} 
})

POST Forms

var form = {
	test: 'test'
}

req.post({ url: 'http://test.com', form: form}, function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) 
	} 
})

POST Json

var data = {
	test: 'test'
}

req.post({ url: 'http://test.com', jsonData: data}, function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) 
	} 
})

Custom HTTP Headers

var headers = {
	'Test-Header': 'test'
}

req.post({ url: 'http://test.com', headers: headers}, function(body, response, err){
	if (!err && response.statusCode == 200) {  
		console.log(body) 
	} 
})

Stream

req.get({url: url, pipe: stream}) 

Timeout

req.get({url: url, timeout: 1000})

Request will be aborted after 1 second if there is no response from server

Keywords

FAQs

Package last updated on 08 May 2017

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