Coder Social home page Coder Social logo

peanoquio / nodejs_http_servers Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 13 KB

A NodeJS sample to show how a server makes a HTTP request to another server

License: MIT License

JavaScript 100.00%
nodejs http-server request expressjs javascript persistent-connections connection-pooling

nodejs_http_servers's Introduction

nodejs_http_servers

A NodeJS sample to show how a server makes a HTTP request to another server

Usage

To run a sample of how this works:

  • Run npm install
  • Run both servers by typing these on the command line: node index.js (port 3000) and node otherServer.js (port 3001)
  • On the server with port 3000, you can make a HTTP request by typing this URL on the browser
http://localhost:3000/route/userId/123/name/guesswho
  • On the same server with port 3000, you can also call this endpoint. The other server (having port 3001)--after receiving the request--will do a redirect to itself with a new endpoint before sending back the response to the calling server. Moreover, the HTTP connection for this will be persistent (with keep-alive and connection pooling).
http://localhost:3000/redirectRoute/userId/123/name/guesswho
  • If you look at the console, you will see that the request is routed to the other server--which in turn also sends a response back to the calling server (that initially made the request)
  • As an alternative, you can also install wrk and make multiple requests to the server. This command line tool is useful for a more detailed benchmarking when making requests.
wrk -t1 -c1 -d1s http://localhost:3000/redirectRoute/userId/123/name/guesswho

Dependencies

The servers uses Express and Request NodeJS modules

License

This is an open source project under the MIT license. For more information, please refer to license.txt

nodejs_http_servers's People

Contributors

peanoquio avatar

Watchers

 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.