Code Monkey home page Code Monkey logo

07-http-server's Introduction

cf Lab 07: Vanilla HTTP Server

Submission Instructions

  • Work in a fork of this repository
  • Work in a branch on your fork
  • Write all of your code in a directory named lab- + <your name> e.g. lab-susan
  • Open a pull request to this repository
  • Submit on canvas a question and observation, how long you spent, and a link to your pull request

Configuration

Configure the root of your repository with the following files and directories. Thoughtfully name and organize any aditional configuration or module files.

  • README.md - contains documentation
  • .env - contains env variables (should be git ignored)
  • .gitignore - contains a robust .gitignore file
  • package.json - contains npm package config
    • create a test script for running tests
    • create a start script for running your server
  • lib/ - contains module definitions
  • test/ - contains unit tests

Feature Tasks

For this assignment you will be building a HTTP server.

Server Module

The server module is responsible for creating an http server defining all route behavior and exporting an interface for starting and stopping the server. It should export an object with start and stop methods. The start and stop methods should each return a promise that resolves on success and rejects on error.

GET /

When a client makes a GET request to / the server should send baack html with a project description and a anchor to /cowsay.

<!DOCTYPE html>
<html>
  <head>
    <title> cowsay </title>  
  </head>
  <body>
   <header>
     <nav>
       <ul> 
         <li><a href="/cowsay">cowsay</a></li>
       </ul>
     </nav>
   <header>
   <main>
     <!-- project description -->
   </main>
  </body>
</html>
GET /cowsay?text={message}

When a client makes a GET request to /cowsay?text={message} the server should parse the querystring for a text key. It should then send a rendered HTML page with a cowsay cow speaking the value of the text query. If their is no text query the cow message should say 'I need something good to say!'.

<!DOCTYPE html>
<html>
  <head>
    <title> cowsay </title>  
  </head>
  <body>
    <h1> cowsay </h1>
    <pre>
      <!-- cowsay.say({text: req.query.text}) -->
    </pre>
  </body>
</html>
POST /api/cowsay

When a client makes a POST request to /api/cowsay it should send JSON that includes {"text": "<message>"}. Notice that there's no URL query parameters in a POST request. POST requests include JSON data in the body of the request.

See how the bodies of POST requests are structured here.

The server should respond with a JSON body {"content": "<cowsay cow>"}.
A response for a valid request should have a status code of 200 and the JSON body

{
  "content": "<cowsay cow text>" 
}

A response for an invalid request should have a status code of 400 and the JSON body...

{
  "error": "invalid request: text query required"
}
Request Response Status Code Response Type Response Body
With out a body 400 JSON {"error": "invalid request: body required"}
With out text property on the body 400 JSON {"error": "invalid request: text query required"}
With text query 200 JSON {"content": "<cowsay cow text>"}

Stretch Goals

Add the ability to change the cowfile on GET /cowsay, GET /api/cowsay, and POST /api/cowsay - ex: dragon, sheep, etc

07-http-server's People

Contributors

geluso avatar

Watchers

 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.