From 40bc4a07922e60d5ccad46a5ab8eb0346409dad8 Mon Sep 17 00:00:00 2001 From: tactonbishop Date: Thu, 4 Aug 2022 08:30:04 +0100 Subject: [PATCH] Last Sync: 2022-08-04 08:30:04 --- .../NodeJS/Modules/Third_party/Helmet.md | 1 + .../NodeJS/REST_APIs/01_GET.md | 0 .../NodeJS/REST_APIs/0_Introduction.md | 52 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 Programming_Languages/NodeJS/Modules/Third_party/Helmet.md create mode 100644 Programming_Languages/NodeJS/REST_APIs/01_GET.md create mode 100644 Programming_Languages/NodeJS/REST_APIs/0_Introduction.md diff --git a/Programming_Languages/NodeJS/Modules/Third_party/Helmet.md b/Programming_Languages/NodeJS/Modules/Third_party/Helmet.md new file mode 100644 index 0000000..58bec37 --- /dev/null +++ b/Programming_Languages/NodeJS/Modules/Third_party/Helmet.md @@ -0,0 +1 @@ +// TODO Add details of Helmet and examples of use. \ No newline at end of file diff --git a/Programming_Languages/NodeJS/REST_APIs/01_GET.md b/Programming_Languages/NodeJS/REST_APIs/01_GET.md new file mode 100644 index 0000000..e69de29 diff --git a/Programming_Languages/NodeJS/REST_APIs/0_Introduction.md b/Programming_Languages/NodeJS/REST_APIs/0_Introduction.md new file mode 100644 index 0000000..a65ed6c --- /dev/null +++ b/Programming_Languages/NodeJS/REST_APIs/0_Introduction.md @@ -0,0 +1,52 @@ +--- +tags: + - Programming_Languages + - backend + - node-js + - express + - REST + - apis +--- + +# Creating a REST API with Node and Express: Introduction + +We are going to use Express to create a [RESTful API](/Databases/RESTful_APIs.md) in Node.js. + +## Request types + +Express provides us with methods corresponding to each of the [HTTP request types](/Databases/HTTP_request_types.md): + +* `app.get()` +* `app.post()` +* `app.put()` +* `app.delete()` + +## Creating an Express instance + +````js +const express = require('express') +const app = express() +```` + +## Our data set + +> Typically when you create a RESTful API you are going to be returning data from a database. For simplicity we are just going simulate this with a simple data array so that we can focus on the Express syntax rather than database handling. + +We will mainly work with the following array of objects: + +````js +const courses = [ + { + id: 1, + name: "First course", + }, + { + id: 2, + name: "Second course", + }, + { + id: 3, + name: "Third course", + }, +]; +```` \ No newline at end of file