Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Introduction

A quick reference on creating service endpoints - an API


When you run this app you will see the message "Cannot GET /".  If you check the developer's tools console output you will see the following error "GET http://localhost:3000/ 404 (Not Found).  You are seeing this message because you have not set up any event handlers (your application has no endpoints)

Setting Request Handlers

A Web Server receives Requests, processes them, and returns a Response.  We need to establish route handling in our application to handle these Requests. 

When developing modern applications we expose what are called ReSTful web services.  These Requests are a GET request that gets data, a POST request that sends data securely, a PUT request that updates data, and a DELETE request that deletes data.

As well as deciding on the Requests, we also need to decide on we will respond with a Response to Requests.

Let's create a simple GET request that says "hello world"

app.get("/sayhello", (req, res, next) => 
{
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.send("Hello World");
});




  • No labels