Giter Site home page Giter Site logo

echo-server's Introduction

Node.js Echo Server

This HTTP server echos the request and response details, and allows you to craft custom HTTP responses based on request parameters.

Getting Started

Requirements: Node http://nodejs.org (version 2.6 or greater)

To run the server:

node echo-server.js

By default echo server runs on port 8124. You can run on a different port with the --port options:

node echo-server.js --port 12345

Usage

Trigger an HTTP 200 response: http://localhost:8124/200

Trigger an HTTP 404 response: http://localhost:8124/404

Trigger an HTTP 404 response with a custom message: http://localhost:8124/404?reasonPhrase=Oh%20No%21

Trigger an HTTP 200 response with a custom header: http://localhost:8124/200?headers.CustomHeader=foo

There are a lot more options and things you can do, including sending parameters as a serialized JSON object, sending an array of responses, and using conditionals to choose the appropriate response. I'll write up more soon, in the meantime, check the source.

Background

Testing client/server communications can be a pain. You either need to embed logging in your code, or fire up WireShark to view the requests/responses. And if you are debugging a server, the start server -> make request -> check logs -> stop server -> edit code cycle can be a real pain. This server helps with these situations by echoing your request/response headers, and also giving you fine-grained control over the response.

One example where this can be useful is testing a CORS preflight request (which is an HTTP OPTION request followed by another HTTP request). Testing this on a regular server would be a pain, but echo-server's "json" parameter gives you fine-grain, almost script-like control over responses or a series of responses.

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.