Coder Social home page Coder Social logo

maddiereddy / assignment_building_the_express_router Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vikingeducation/assignment_building_the_express_router

0.0 1.0 0.0 10 KB

Build the core features of the Express router

JavaScript 100.00%

assignment_building_the_express_router's Introduction

assignment_building_the_express_router

Build the core features of the Express router

Maddie Rajavasireddy

Assignment description:

  1. Hello Express Router: implement an Express module that creates an app object and enables it to:
    Register GET routes with associated callbacks with app.get()
    Start up a server with app.listen()
  2. Parsing Path Patterns: set up a path parser to take a given path pattern (e.g. /foo/:bar) and parse it into an object usable by the router.
    For each given pattern, your router needs:
    - A way to match a URL path to the pattern
    - A way to extract parameters from the URL
    - A way to give those parameter values the names from the pattern (e.g. the pattern /foo/:bar would match /foo/1 and yield { bar: 1 } as the params)
  3. Parametrized Routing: set up the router to allow parameterized routing for GET requests.
    Use your path pattern parser to parse a given pattern passed to app.get
    Save the result so that when your server receives a request it can check if it matches that pattern
    - Check both the method and URL of the request object (i.e. req.method and req.url)
    When a request is received by the server, use the saved regex and parameter names to check if that request URL matches the pattern
    - The app may have many different patterns so you'll have to iterate over them and use the first one that matches
    When you find a pattern that matches:
    - Extract the named parameters from the URL and attach them to the req object as req.params (req.params should be an object where each key is the parameter name and the value is the value from the request URL)
    - Invoke the callback that was passed with it when you called app.get(pathPattern, callback)
    Be sure to pass that callback the req and res objects
    Verify that you can invoke the callbacks given to the following routes and extract their named parameters with the correct values:
    - /foo/:bar/
    - /foo/:bar/fiz/:baz
  4. Enabling POST requests:
    Now enable app.post to register callbacks for the paths it is passed
    - This should register a route with the router with an associated callback the same way app.get was implemented
    Verify you can send a POST request to your app and the correct callback is invoked
  5. Parsing POST Data:
    Enable the application to parse POST data into an object
    Attach the parsed object onto the req as req.body
    Verify that one can submit shallow POST data (e.g. foo=bar) and it results in the correct object being created at req.body
    - Note don't attempt to parse nested POST data here (e.g. foo[bar]=fiz) You can send a POST request to your server via the command-line with curl like this: $ curl -d "foo=bar" http://localhost:3000 6. Enabling RESTful HTTP Methods:
    Enable the app object to support the following methods:
    - app.put
    - app.patch
    - app.delete
    These should all register a route with the router with an associated callback the same way app.get was implemented
    Verify that one can submit a request to the server using each of these HTTP methods

assignment_building_the_express_router's People

Contributors

bideowego avatar maddiereddy 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.