Coder Social home page Coder Social logo

codaisseur-week5-day3-middleware-bodyparser's Introduction

codaisseur-week5-day3-middleware-bodyparser

Exercise: Try it out module: express-bodyparser.js HIGHTLIGHT: using express and body-parser : app.use, app.post

Create a Node.js project and install the following dependencies: [email protected] [email protected] this project requires 'npm install express body-parser' in terminal

Copy the above example code into a new JavaScript file and run the program. Test the code with this command: http -v :4000 foo=bar. Thanks to the -v flag you should see both the HTTP request and response Confirm that the api logs the request body to the console Now make a similar request but using HTTPie's "form" mode: http -v --form :4000 foo=bar Confirm that the HTTP request is of the type application/x-www-form-urlencoded and that the express application logs the same information as before.


Exercise: adding ERROR HANDLER: module: express-errorhandler.js Reuse the Node.js project from the previous exercise. Create a new JavaScript file and include the following code: const express = require('express') const app = express() const port = 3000 app.get('/', (req, res, next) => { // Your code goes here }) app.listen(port, () => console.log(Example app listening on port ${port}!)) Implement the logic in the handler function so that 50% of the time (using Math.random()), we trigger the built-in error handler, and the other 50% of the time we respond with the text "Ok". Call your endpoint several times and confirm that 50% of the time you get an error page (HTML).

codaisseur-week5-day3-middleware-bodyparser's People

Contributors

jendhordejan 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.