GithubHelp home page GithubHelp logo

node-request-as-curl's Introduction

request-as-curl

[NPM Version] (https://npmjs.org/package/request-as-curl) [Build Status] (https://travis-ci.org/azproduction/node-request-as-curl) [Coverage Status] (https://coveralls.io/r/azproduction/node-request-as-curl) [Dependency Status] (https://gemnasium.com/azproduction/node-request-as-curl)

It serializes http.ClientRequest as curl(1) command string. This is like Copy as cURL, but for node.

Installation

request-as-curl can be installed using npm:

npm install request-as-curl

Example

var curlify = require('request-as-curl'),
    request = require('express'),
    data = {data: 'data'};

var req = request('http://google.com/', {method: 'POST', json: data}, function (error, response, expected) {
    // Note: req.req!
    curlify(req.req, data);
    // curl 'http://google.com' -H 'accept: application/json' -H 'content-type: application/json' -H 'connection: keep-alive' --data '{"data":"data"}' --compressed
});
var curlify = require('request-as-curl'),
    app = require('express')();

app.get('/', function (req) {
    curlify(req);
    // curl 'http://localhost/pewpew' -H 'x-real-ip: 127.0.0.1' -H 'x-forwarded-for: 127.0.0.1' -H 'x-nginx-proxy: true' -H 'connection: close' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:25.0) Gecko/20100101 Firefox/25.0' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'accept-language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3' -H 'accept-encoding: gzip, deflate' -H 'cache-control: max-age=0' --compressed
});

app.listen();

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.