Giter Club home page Giter Club logo

http-with-net's Introduction

LAB: HTTP with net

Using only the net module create an HTTP server that responds with different messages based on path.

Before you begin

Refer to Getting Started in the lab submission instructions for complete setup, configuration, deployment, and submission instructions.

Getting Started

The starter-code includes basic scaffolding and tests for parseRequest and createResponse.

Requirements

Parse a Request

parseRequest takes a rawRequest (an HTTP request message). It should take that rawRequest and return an object with body, method, and path from the rawRequest.

Create a Response

module.exports = ({ body = '', contentType = 'text/html', status = '200 OK' }) => { return ` HTTP/1.1 ${status} Accept-Ranges: bytes Content-Length: ${body.length} Content-Type: ${contentType}

${body} `.trim(); };

createResponse takes an object with body, contentText, and status. It should use that information to construct an HTTP response message. Make sure to set the:

  • status
  • Content-Length header
  • Content-Type header
  • HTTP body

Handle Requests

path method body
/ GET plain text "hi"
/echo POST status code 200 and plain text with the request body
/red GET html with an h1 and the word red
/green GET html with an h1 and the word green
/blue GET html with an h1 and the word blue

Everything else respond with 404 and a not found HTML page.

Testing Requests

Use supertest to test your routes.

Rubric

  • parseRequest - 4 points
  • createResponse - 4 points
  • handle routes - 2 points

Assignment Submission Instructions

Refer to the the lab submission instructions for the complete lab submission process and expectations

http-with-net's People

Contributors

cnspangler avatar dependabot[bot] avatar

Watchers

James Cloos avatar  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.