From 1f0e3dd0257f9948d9dc4ca0bebc3226d2cf2d4f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 Nov 2024 13:58:54 +0530 Subject: [PATCH 01/24] feat: decide on an appropriate location for the lesson --- nodeJS/apis/RESTful_APIs.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 nodeJS/apis/RESTful_APIs.md diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md new file mode 100644 index 00000000000..e69de29bb2d From cd12dcccd1cdfffbe8f38b905095edaf3c1d0dfd Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 Nov 2024 18:37:37 +0530 Subject: [PATCH 02/24] feat: add lesson objectives --- nodeJS/apis/RESTful_APIs.md | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index e69de29bb2d..ecce0d69656 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -0,0 +1,71 @@ +### Introduction + +A BRIEF INTRODUCTION. + +### Lesson overview + +This section contains a general overview of topics that you will learn in this lesson. + +- Understand what makes an API RESTful. +- Detail the naming conventions for RESTful API endpoints. +- Reinforcing what HTTP methods/verbs are. +- Recognising RESTful APIs from examples. + +### CUSTOM SECTION HEADING + +CUSTOM SECTION CONTENT. + +#### Note box variations + +
+ +#### A sample title + +A sample note box. + +
+ +
+ +#### level 4 heading for title is recommended + +A sample note box, variation: tip. + +
+ +
+ +#### But title is also optional + +A sample note box, variation: warning. + +
+ +
+ +A sample note box, variation: critical. + +
+ +### Assignment + +
+ +1. A RESOURCE ITEM + - AN INSTRUCTION ITEM +1. A PRACTICE ITEM + - A TASK ITEM + +
+ +### Knowledge check + +The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge. + +- [A KNOWLEDGE CHECK QUESTION](A-KNOWLEDGE-CHECK-URL) + +### Additional resources + +This section contains helpful links to related content. It isn't required, so consider it supplemental. + +- It looks like this lesson doesn't have any additional resources yet. Help us expand this section by contributing to our curriculum. From 42e3f3965dc05869827e1cc61d91111125b12543 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 Nov 2024 19:07:06 +0530 Subject: [PATCH 03/24] feat: add another point in lesson objectives --- nodeJS/apis/RESTful_APIs.md | 1 + 1 file changed, 1 insertion(+) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index ecce0d69656..61ec79d4aed 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -9,6 +9,7 @@ This section contains a general overview of topics that you will learn in this l - Understand what makes an API RESTful. - Detail the naming conventions for RESTful API endpoints. - Reinforcing what HTTP methods/verbs are. +- Understand the different components of an URL. - Recognising RESTful APIs from examples. ### CUSTOM SECTION HEADING From ef55ab48fe8a975e9e1429ae7578b67f9dd3d256 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 16 Nov 2024 19:27:41 +0530 Subject: [PATCH 04/24] feat: add content to the what is an api section --- nodeJS/apis/RESTful_APIs.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 61ec79d4aed..61e8741d6e1 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -12,9 +12,15 @@ This section contains a general overview of topics that you will learn in this l - Understand the different components of an URL. - Recognising RESTful APIs from examples. -### CUSTOM SECTION HEADING +### So what is an API? -CUSTOM SECTION CONTENT. +Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. When you write a program, you can programmatically open up a browser and try to access a website's data. But usually, you don't have to bother with that - you can ask for the data directly by using the website's API. + +Up until now you have been creating a server to serve your assets like HTML, CSS and JavaScript. But you have also learnt about React and client-side navigation - here is where we come to understand why. In about the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. + +This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit to this architecture lies in its seperation of the business logic and view logic. This allows you to use a singular backend as a source of data for whichever form of frontend application(s) you want. You can send data to a website, a desktop app and a mobile app with the same backend. + +As mentioned, generally, your backend application will need to send data to your frontend. The most popular way to do so by far is in JSON. #### Note box variations From bf95ec756e8032a2aed34827dbfcd693ca6f3807 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 16 Nov 2024 20:13:41 +0530 Subject: [PATCH 05/24] feat: relocate an introduction --- nodeJS/apis/RESTful_APIs.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 61e8741d6e1..9c7237890a5 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -1,6 +1,8 @@ ### Introduction -A BRIEF INTRODUCTION. +Up until now you have been creating a server to serve your assets like HTML, CSS and JavaScript. But you have also learnt about React and client-side navigation - here is where we come to understand why. In about the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. + +This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit to this architecture lies in its seperation of the business logic and view logic. This allows you to use a singular backend as a source of data for whichever form of frontend application(s) you want. You can send data to a website, a desktop app and a mobile app with the same backend. ### Lesson overview @@ -16,10 +18,6 @@ This section contains a general overview of topics that you will learn in this l Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. When you write a program, you can programmatically open up a browser and try to access a website's data. But usually, you don't have to bother with that - you can ask for the data directly by using the website's API. -Up until now you have been creating a server to serve your assets like HTML, CSS and JavaScript. But you have also learnt about React and client-side navigation - here is where we come to understand why. In about the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. - -This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit to this architecture lies in its seperation of the business logic and view logic. This allows you to use a singular backend as a source of data for whichever form of frontend application(s) you want. You can send data to a website, a desktop app and a mobile app with the same backend. - As mentioned, generally, your backend application will need to send data to your frontend. The most popular way to do so by far is in JSON. #### Note box variations From 853216ed36b355329c8016534572d97e97c2f3f1 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 09:45:20 +0530 Subject: [PATCH 06/24] fix: change sentences about in introduction and rest api sections --- nodeJS/apis/RESTful_APIs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 9c7237890a5..5f2e963516e 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -2,7 +2,7 @@ Up until now you have been creating a server to serve your assets like HTML, CSS and JavaScript. But you have also learnt about React and client-side navigation - here is where we come to understand why. In about the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. -This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit to this architecture lies in its seperation of the business logic and view logic. This allows you to use a singular backend as a source of data for whichever form of frontend application(s) you want. You can send data to a website, a desktop app and a mobile app with the same backend. +This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit to this architecture lies in its seperation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app and a mobile app with the same backend. ### Lesson overview From e17eba21f0e4d9ed62402ce0c412cd0db86f9ab8 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 09:52:16 +0530 Subject: [PATCH 07/24] feat: add a http section --- nodeJS/apis/RESTful_APIs.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 5f2e963516e..b07652cad69 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -14,11 +14,17 @@ This section contains a general overview of topics that you will learn in this l - Understand the different components of an URL. - Recognising RESTful APIs from examples. -### So what is an API? +### HTTP -Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. When you write a program, you can programmatically open up a browser and try to access a website's data. But usually, you don't have to bother with that - you can ask for the data directly by using the website's API. +HTTP can be roughly defined as the layer that acts as a protocol for a request-and-response mode of communication between a client (here, browser) and a server. If you open up the network tab in the developer tools of your browser and refresh the page, you will notice a long list of items. These are loosely referred to as "resources" - a thing in the database of your server, that the browser is asking for, as a request, and getting as a response. -As mentioned, generally, your backend application will need to send data to your frontend. The most popular way to do so by far is in JSON. +Clicking on any one of these items will let you see further details about them. Notice that each of these requests and responses have a header and (usually) a body component. The header is responsible for information about the request/reponse itself, like the address to send/receive from, the kind of information being carried/asked for, and more. The body on the other hand contains the data added to the request/response, like the response to a form or authentication tokens in requests or the page itself in responses. + +### RESTful APIs + +Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional methods to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). The exact definition of REST might be a little complicated, but for us, it states that there is a set + +As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON. #### Note box variations @@ -56,8 +62,7 @@ A sample note box, variation: critical.
-1. A RESOURCE ITEM - - AN INSTRUCTION ITEM +1. [[Add the tutplus content as a refresher to HTTP stuff, and probably the request/response checker?]] 1. A PRACTICE ITEM - A TASK ITEM From 93ead333df0833f69009a1e3fc74fc417e65943a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 10:54:05 +0530 Subject: [PATCH 08/24] feat: add CRUD and HTTP methods section --- nodeJS/apis/RESTful_APIs.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index b07652cad69..0f69e28a898 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -20,6 +20,21 @@ HTTP can be roughly defined as the layer that acts as a protocol for a request-a Clicking on any one of these items will let you see further details about them. Notice that each of these requests and responses have a header and (usually) a body component. The header is responsible for information about the request/reponse itself, like the address to send/receive from, the kind of information being carried/asked for, and more. The body on the other hand contains the data added to the request/response, like the response to a form or authentication tokens in requests or the page itself in responses. +### CRUD and HTTP methods + +By now you have probably heard about the word CRUD. Broadly, an API is responsible to provide four functions on any resource - **c**reating it, **r**eading about it, **u**pdating it and **d**eleting it. CRUD describes the actions that you can have on a resource, if your action cannot be described by any of these four, then it could probably be its own model. A key component of any request is to understand what kind of function it wants, amongst these four. + +Instead of having a naming convention like `/getPosts` or `/setPosts`, a request directly refers to the resource itself (here, `/posts`) and a corresponding HTTP method (colloquially called HTTP verbs, since they are verbs, grammatically). The methods are as follows: + +| Method | Action | Example | +| ------ | ------ | ----------------------------------------------- | +| POST | Create | `POST /posts` - Creates a new blog post | +| GET | Read | `GET /posts/:postid` - Fetches a single post | +| PUT | Update | `PUT /posts/:postid` - Updates a single post | +| DELETE | Delete | `DELETE /posts/:postid` - Deletes a single post | + +There are usually 2 URI's for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URIs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. + ### RESTful APIs Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional methods to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). The exact definition of REST might be a little complicated, but for us, it states that there is a set From ed02ab14fc7ab903286ddc7142690e1a7acd31b4 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 11:47:25 +0530 Subject: [PATCH 09/24] feat: add a section on http codes --- nodeJS/apis/RESTful_APIs.md | 40 +++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 0f69e28a898..fdc76dcbdc8 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -35,6 +35,43 @@ Instead of having a naming convention like `/getPosts` or `/setPosts`, a request There are usually 2 URI's for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URIs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. +### HTTP response codes + +Every response from a server has a response code that provides quick and basic context regarding the response itself to the client. They are classified into five classes: + +#### Status codes 100 - 199: Informational responses + +Introduced by the HTTP/1.1 standard, these simply represent that a request was received and understood, mostly used on a provisional basis while the request processing continues. It simply alerts the client to wait on a final response. + +#### Status codes 200 - 299: Successful responses + +These tell the client that a request was successfully received and processed. + +- `200 OK`: It is the default to indicate a successful request. The result and response depends on the HTTP method, like sending the resource in the body for a `GET` request or describing the created entity for a `POST` request. +- `202 Accepted`: Indicates that a request was accepted but is being processed. No further context is attached to the response, like if it will be acted on eventually or not. + +#### Status codes 300 - 399: Redirection messages + +Whenever additional action is needed to complete the request, it is indicated to the client with this class of status codes. A major use case for these is URL redirection. + +- `301 Moved Permanently`: Denotes the permanent relocation of any resource to a different URL, while adding the new URL to the response. + +#### Status codes 400 - 499: Client error responses + +These are used to report faults made by the client, like requesting for a non-existent resource or making a bad request, usually accompanied by an explanation about the fault itself and whether it is temporary or permanent. + +- `400 Bad Request`: The request is not processed due to a client error like malformed request syntax or invalid request messages. +- `401 Unauthorised`: Slightly misleading, semantically it means that the response is "unauthenticated". The client must add the proper, non-malformed authentication credentials for a resource. +- `403 Forbidden`: Indicates that the server refuses to act on the request due to a broad set of reasons from the user missing necessary permissions to attempts on a forbidden or impossible action. Unlike `401 Unauthorised`, the identity of the client is known to the server. +- `404 Not Found`: The most popular status code, it indicates that a resource does not exist, even if the URL is valid. + +#### Status codes 500 - 599: Server error responses + +Indicates when the server fails to process a request. + +- `500 Internal Server Error`: A generic catch-all status code used to indicate that an internal error faced by the server while processing the request. +- `501 Not Implemented`: The server lacks the capabilities to fulfill the request or is unable to recognise the request method. + ### RESTful APIs Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional methods to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). The exact definition of REST might be a little complicated, but for us, it states that there is a set @@ -78,8 +115,7 @@ A sample note box, variation: critical.
1. [[Add the tutplus content as a refresher to HTTP stuff, and probably the request/response checker?]] -1. A PRACTICE ITEM - - A TASK ITEM +1. [[Add further details on response codes. What do I cover as "important/common"?]]
From 96d18b32c51e650a12ecc411bba06a92077e9635 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 12:14:55 +0530 Subject: [PATCH 10/24] feat: add a section on urls --- nodeJS/apis/RESTful_APIs.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index fdc76dcbdc8..ffc8533d02c 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -72,6 +72,23 @@ Indicates when the server fails to process a request. - `500 Internal Server Error`: A generic catch-all status code used to indicate that an internal error faced by the server while processing the request. - `501 Not Implemented`: The server lacks the capabilities to fulfill the request or is unable to recognise the request method. +### URL + +By now, I'm sure we know what URLs are, but as a quick refresher, let's check one out. It consists of a simple structure of a few components. Take the following as an example. + +```text +http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anchor +``` + +- Here, `http` is the protocol. Some others that you might notice includes https, ftp and so on. +- The host name is `subdomain.domain.com` +- The subdomain here is `sub` +- The domain name is `domain.com` +- `1234` indicates the port. The browser usually hides this, since it defaults to `80`, which is the default port for web servers. +- `/path/to/resource` denotes the resource path which refers to a resource location within the server. +- There are some query parameters here: `?query=something¶m=something`. Query string parameters start with a question mark (`?`), following a `key=value` format and seperated by an ampersand (`&`). There can be any number of parameters and they are generally used by the server to spot the right resource. +- The `#anchor` is called a fragment or a named anchor. It is used to refer to an internal section within a web document. + ### RESTful APIs Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional methods to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). The exact definition of REST might be a little complicated, but for us, it states that there is a set From 19c6b972c1da6cfd0e7566e9b02dbb331f6a03db Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 15:38:10 +0530 Subject: [PATCH 11/24] feat: add a section on RESTful APIs --- nodeJS/apis/RESTful_APIs.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index ffc8533d02c..072f595a6f3 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -72,7 +72,7 @@ Indicates when the server fails to process a request. - `500 Internal Server Error`: A generic catch-all status code used to indicate that an internal error faced by the server while processing the request. - `501 Not Implemented`: The server lacks the capabilities to fulfill the request or is unable to recognise the request method. -### URL +### URLs By now, I'm sure we know what URLs are, but as a quick refresher, let's check one out. It consists of a simple structure of a few components. Take the following as an example. @@ -91,9 +91,11 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch ### RESTful APIs -Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional methods to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). The exact definition of REST might be a little complicated, but for us, it states that there is a set +Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API, RESTful (adhere to the constraints set by REST). -As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON. +Since we have already talked about seperating the client and the server, it fufills the first constraint of REST - the two are well defined as the frontend and the backend. Further constraints like stateless-ness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organisation of endpoint URIs (Uniform Resource Identifiers) with respect to our resources. + +As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON, primarily due to the ease of parsing it with JavaScript. So all we need to do is to replace our HTML and serve JSON instead. All that you have to do, thus, is to pass your information to [`res.json()`](https://expressjs.com/en/4x/api.html#res.json) instead of [`res.send()`](https://expressjs.com/en/4x/api.html#res.send) or [`res.render()`](https://expressjs.com/en/4x/api.html#res.render). #### Note box variations From eb3b443860ec34fba429a9ec386adb3f36c993f6 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 16:03:10 +0530 Subject: [PATCH 12/24] feat: add a knowledge check --- nodeJS/apis/RESTful_APIs.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 072f595a6f3..9c10134c8e2 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -142,7 +142,12 @@ A sample note box, variation: critical. The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge. -- [A KNOWLEDGE CHECK QUESTION](A-KNOWLEDGE-CHECK-URL) +- [What is CRUD?](https://www.codecademy.com/article/what-is-crud) +- [What are the HTTP methods and where are they used?](#crud-and-http-methods) +- [Which HTTP method does each letter in CRUD (Create, Read, Update, Delete) correspond to?](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/#h-use-nouns-instead-of-verbs-in-endpoint-paths) +- [What part of an URL is referred to as the query paramters?](#urls) +- [Which HTTP response status code is used to indicate the permanent relocation of a resource?](#status-codes-300---399-redirection-messages) +- [What is an API and how do you make it RESTful](#restful-apis) ### Additional resources From 680cd2bca995ecc45622d0531489542ef143f10f Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 16:03:25 +0530 Subject: [PATCH 13/24] feat: add additional resources --- nodeJS/apis/RESTful_APIs.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 9c10134c8e2..9064334e620 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -8,10 +8,10 @@ This technique is sometimes referred to as the [Jamstack](https://jamstack.org/w This section contains a general overview of topics that you will learn in this lesson. -- Understand what makes an API RESTful. - Detail the naming conventions for RESTful API endpoints. -- Reinforcing what HTTP methods/verbs are. +- Reinforcing what HTTP methods/verbs and status codes are. - Understand the different components of an URL. +- Understand what makes an API RESTful. - Recognising RESTful APIs from examples. ### HTTP @@ -35,7 +35,7 @@ Instead of having a naming convention like `/getPosts` or `/setPosts`, a request There are usually 2 URI's for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URIs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. -### HTTP response codes +### HTTP response status codes Every response from a server has a response code that provides quick and basic context regarding the response itself to the client. They are classified into five classes: @@ -153,4 +153,5 @@ The following questions are an opportunity to reflect on key topics in this less This section contains helpful links to related content. It isn't required, so consider it supplemental. -- It looks like this lesson doesn't have any additional resources yet. Help us expand this section by contributing to our curriculum. +- [HTTP Request/Response Basics](http://justahelp.blogspot.com/2013/09/http-requestresponse-basics.html) from Pralay Roy goes into further detail about their lifecycle and anatomy with best practices. +- This [CodeAcademy article discussing REST](https://www.codecademy.com/article/what-is-rest) strikes a healthy balance between relatability and strict definitions. From 6fa51cf9e150ca99b6d9758dbb27625c11bbea95 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 16:24:57 +0530 Subject: [PATCH 14/24] feat: add assignments --- nodeJS/apis/RESTful_APIs.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 9064334e620..68be3ec43bb 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -133,8 +133,11 @@ A sample note box, variation: critical.
-1. [[Add the tutplus content as a refresher to HTTP stuff, and probably the request/response checker?]] -1. [[Add further details on response codes. What do I cover as "important/common"?]] +1. Check out the [list of HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) listed in the MDN documention. While you will never use some codes, you will notice a lot of useful ones. +1. Read up on the following resources about REST and RESTful APIs. + - Go through the following [CodeAcademy article discussing REST](https://www.codecademy.com/article/what-is-rest). It discusses the definitions of REST and gives some good examples to explain important keywords. + - Check out this [StackOverflow article about RESTful API design](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design). If you want to code along, do remember that the `body-parser` middleware mentioned here is incorporated into the ExpressJS package itself since 4.16.x and is no longer necessary. +1. Code along with this tutorial on [setting up a REST API with ExpressJS](https://www.robinwieruch.de/node-express-server-rest-api/). Go through this article as thoroughly as possible since it discusses some key details like organisation, middlewares and links some important resources at the end.
@@ -154,4 +157,3 @@ The following questions are an opportunity to reflect on key topics in this less This section contains helpful links to related content. It isn't required, so consider it supplemental. - [HTTP Request/Response Basics](http://justahelp.blogspot.com/2013/09/http-requestresponse-basics.html) from Pralay Roy goes into further detail about their lifecycle and anatomy with best practices. -- This [CodeAcademy article discussing REST](https://www.codecademy.com/article/what-is-rest) strikes a healthy balance between relatability and strict definitions. From b0f4019f151de68a5846d01130910215291bd597 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 16:25:30 +0530 Subject: [PATCH 15/24] fix: clean up template text --- nodeJS/apis/RESTful_APIs.md | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 68be3ec43bb..cd9cb767cd5 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -97,38 +97,6 @@ Since we have already talked about seperating the client and the server, it fufi As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON, primarily due to the ease of parsing it with JavaScript. So all we need to do is to replace our HTML and serve JSON instead. All that you have to do, thus, is to pass your information to [`res.json()`](https://expressjs.com/en/4x/api.html#res.json) instead of [`res.send()`](https://expressjs.com/en/4x/api.html#res.send) or [`res.render()`](https://expressjs.com/en/4x/api.html#res.render). -#### Note box variations - -
- -#### A sample title - -A sample note box. - -
- -
- -#### level 4 heading for title is recommended - -A sample note box, variation: tip. - -
- -
- -#### But title is also optional - -A sample note box, variation: warning. - -
- -
- -A sample note box, variation: critical. - -
- ### Assignment
From c932b25dc43e2405308507eea8ffbbd30fa3a730 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Nov 2024 16:44:16 +0530 Subject: [PATCH 16/24] fix: clean up grammar --- nodeJS/apis/RESTful_APIs.md | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index cd9cb767cd5..1142bccbabd 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -1,8 +1,8 @@ ### Introduction -Up until now you have been creating a server to serve your assets like HTML, CSS and JavaScript. But you have also learnt about React and client-side navigation - here is where we come to understand why. In about the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. +Up until now, you have been creating a server to serve your assets like HTML, CSS, and JavaScript. But you have also learned about React and client-side navigation - here is where we come to understand why. In the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. -This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit to this architecture lies in its seperation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app and a mobile app with the same backend. +This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit of this architecture lies in its separation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app, and a mobile app with the same backend. ### Lesson overview @@ -10,7 +10,7 @@ This section contains a general overview of topics that you will learn in this l - Detail the naming conventions for RESTful API endpoints. - Reinforcing what HTTP methods/verbs and status codes are. -- Understand the different components of an URL. +- Understand the different components of a URL. - Understand what makes an API RESTful. - Recognising RESTful APIs from examples. @@ -18,22 +18,22 @@ This section contains a general overview of topics that you will learn in this l HTTP can be roughly defined as the layer that acts as a protocol for a request-and-response mode of communication between a client (here, browser) and a server. If you open up the network tab in the developer tools of your browser and refresh the page, you will notice a long list of items. These are loosely referred to as "resources" - a thing in the database of your server, that the browser is asking for, as a request, and getting as a response. -Clicking on any one of these items will let you see further details about them. Notice that each of these requests and responses have a header and (usually) a body component. The header is responsible for information about the request/reponse itself, like the address to send/receive from, the kind of information being carried/asked for, and more. The body on the other hand contains the data added to the request/response, like the response to a form or authentication tokens in requests or the page itself in responses. +Clicking on any one of these items will let you see further details about them. Notice that each of these requests and responses has a header and (usually) a body component. The header is responsible for information about the request/response itself, like the address to send/receive from, the kind of information being carried/asked for, and more. The body on the other hand contains the data added to the request/response, like the response to a form or authentication tokens in requests or the page itself in responses. ### CRUD and HTTP methods -By now you have probably heard about the word CRUD. Broadly, an API is responsible to provide four functions on any resource - **c**reating it, **r**eading about it, **u**pdating it and **d**eleting it. CRUD describes the actions that you can have on a resource, if your action cannot be described by any of these four, then it could probably be its own model. A key component of any request is to understand what kind of function it wants, amongst these four. +By now you have probably heard about the word CRUD. Broadly, an API is responsible for providing four functions on any resource - **c**reating it, **r**eading about it, **u**pdating it, and **d**eleting it. CRUD describes the actions that you can have on a resource, if your action cannot be described by any of these four, then it could probably be its own model. A key component of any request is to understand what kind of function it wants, amongst these four. Instead of having a naming convention like `/getPosts` or `/setPosts`, a request directly refers to the resource itself (here, `/posts`) and a corresponding HTTP method (colloquially called HTTP verbs, since they are verbs, grammatically). The methods are as follows: -| Method | Action | Example | +| Method | Action | Example                                         | | ------ | ------ | ----------------------------------------------- | -| POST | Create | `POST /posts` - Creates a new blog post | -| GET | Read | `GET /posts/:postid` - Fetches a single post | -| PUT | Update | `PUT /posts/:postid` - Updates a single post | +| POST   | Create | `POST /posts` - Creates a new blog post         | +| GET    | Read   | `GET /posts/:postid` - Fetches a single post    | +| PUT    | Update | `PUT /posts/:postid` - Updates a single post    | | DELETE | Delete | `DELETE /posts/:postid` - Deletes a single post | -There are usually 2 URI's for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URIs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. +There are usually 2 URIs for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URIs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post, or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. ### HTTP response status codes @@ -41,14 +41,14 @@ Every response from a server has a response code that provides quick and basic c #### Status codes 100 - 199: Informational responses -Introduced by the HTTP/1.1 standard, these simply represent that a request was received and understood, mostly used on a provisional basis while the request processing continues. It simply alerts the client to wait on a final response. +Introduced by the HTTP/1.1 standard, these simply represent that a request was received and understood, mostly used on a provisional basis while the request processing continues. It simply alerts the client to wait for a final response. #### Status codes 200 - 299: Successful responses These tell the client that a request was successfully received and processed. -- `200 OK`: It is the default to indicate a successful request. The result and response depends on the HTTP method, like sending the resource in the body for a `GET` request or describing the created entity for a `POST` request. -- `202 Accepted`: Indicates that a request was accepted but is being processed. No further context is attached to the response, like if it will be acted on eventually or not. +- `200 OK`: It is the default to indicate a successful request. The result and response depend on the HTTP method, like sending the resource in the body for a `GET` request or describing the created entity for a `POST` request. +- `202 Accepted`: Indicates that a request was accepted but is being processed. No further context is attached to the response, like whether it will be acted on eventually or not. #### Status codes 300 - 399: Redirection messages @@ -58,19 +58,19 @@ Whenever additional action is needed to complete the request, it is indicated to #### Status codes 400 - 499: Client error responses -These are used to report faults made by the client, like requesting for a non-existent resource or making a bad request, usually accompanied by an explanation about the fault itself and whether it is temporary or permanent. +These are used to report faults made by the client, like requesting a non-existent resource or making a bad request, usually accompanied by an explanation about the fault itself and whether it is temporary or permanent. - `400 Bad Request`: The request is not processed due to a client error like malformed request syntax or invalid request messages. - `401 Unauthorised`: Slightly misleading, semantically it means that the response is "unauthenticated". The client must add the proper, non-malformed authentication credentials for a resource. - `403 Forbidden`: Indicates that the server refuses to act on the request due to a broad set of reasons from the user missing necessary permissions to attempts on a forbidden or impossible action. Unlike `401 Unauthorised`, the identity of the client is known to the server. -- `404 Not Found`: The most popular status code, it indicates that a resource does not exist, even if the URL is valid. +- `404 Not Found`: The most popular status code, indicates that a resource does not exist, even if the URL is valid. #### Status codes 500 - 599: Server error responses Indicates when the server fails to process a request. -- `500 Internal Server Error`: A generic catch-all status code used to indicate that an internal error faced by the server while processing the request. -- `501 Not Implemented`: The server lacks the capabilities to fulfill the request or is unable to recognise the request method. +- `500 Internal Server Error`: A generic catch-all status code used to indicate an internal error faced by the server while processing the request. +- `501 Not Implemented`: The server lacks the capabilities to fulfill the request or is unable to recognize the request method. ### URLs @@ -80,20 +80,20 @@ By now, I'm sure we know what URLs are, but as a quick refresher, let's check on http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anchor ``` -- Here, `http` is the protocol. Some others that you might notice includes https, ftp and so on. -- The host name is `subdomain.domain.com` +- Here, `http` is the protocol. Some others that you might notice include https, ftp, and so on. +- The hostname is `subdomain.domain.com` - The subdomain here is `sub` - The domain name is `domain.com` - `1234` indicates the port. The browser usually hides this, since it defaults to `80`, which is the default port for web servers. - `/path/to/resource` denotes the resource path which refers to a resource location within the server. -- There are some query parameters here: `?query=something¶m=something`. Query string parameters start with a question mark (`?`), following a `key=value` format and seperated by an ampersand (`&`). There can be any number of parameters and they are generally used by the server to spot the right resource. +- There are some query parameters here: `?query=something¶m=something`. Query string parameters start with a question mark (`?`), following a `key=value` format and separated by an ampersand (`&`). There can be any number of parameters and they are generally used by the server to spot the right resource. - The `#anchor` is called a fragment or a named anchor. It is used to refer to an internal section within a web document. ### RESTful APIs -Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learnt in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API, RESTful (adhere to the constraints set by REST). +Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learned in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API, RESTful (adhere to the constraints set by REST). -Since we have already talked about seperating the client and the server, it fufills the first constraint of REST - the two are well defined as the frontend and the backend. Further constraints like stateless-ness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organisation of endpoint URIs (Uniform Resource Identifiers) with respect to our resources. +Since we have already talked about separating the client and the server, it fulfills the first constraint of REST - the two are well-defined as the frontend and the backend. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URIs (Uniform Resource Identifiers) with respect to our resources. As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON, primarily due to the ease of parsing it with JavaScript. So all we need to do is to replace our HTML and serve JSON instead. All that you have to do, thus, is to pass your information to [`res.json()`](https://expressjs.com/en/4x/api.html#res.json) instead of [`res.send()`](https://expressjs.com/en/4x/api.html#res.send) or [`res.render()`](https://expressjs.com/en/4x/api.html#res.render). @@ -101,11 +101,11 @@ As mentioned, usually your backend application will need to send data to your fr
-1. Check out the [list of HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) listed in the MDN documention. While you will never use some codes, you will notice a lot of useful ones. +1. Check out the [list of HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) listed in the MDN documentation. While you will never use some codes, you will notice a lot of useful ones. 1. Read up on the following resources about REST and RESTful APIs. - - Go through the following [CodeAcademy article discussing REST](https://www.codecademy.com/article/what-is-rest). It discusses the definitions of REST and gives some good examples to explain important keywords. - - Check out this [StackOverflow article about RESTful API design](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design). If you want to code along, do remember that the `body-parser` middleware mentioned here is incorporated into the ExpressJS package itself since 4.16.x and is no longer necessary. -1. Code along with this tutorial on [setting up a REST API with ExpressJS](https://www.robinwieruch.de/node-express-server-rest-api/). Go through this article as thoroughly as possible since it discusses some key details like organisation, middlewares and links some important resources at the end. +   - Go through the following [CodeAcademy article discussing REST](https://www.codecademy.com/article/what-is-rest). It discusses the definitions of REST and gives some good examples to explain important keywords. +   - Check out this [StackOverflow article about RESTful API design](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design). If you want to code along, do remember that the `body-parser` middleware mentioned here has been incorporated into the ExpressJS package itself since 4.16.x and is no longer necessary. +1. Code along with this tutorial on [setting up a REST API with ExpressJS](https://www.robinwieruch.de/node-express-server-rest-api/). Go through this article as thoroughly as possible since it discusses some key details like organization, middlewares, and links some important resources at the end.
@@ -116,7 +116,7 @@ The following questions are an opportunity to reflect on key topics in this less - [What is CRUD?](https://www.codecademy.com/article/what-is-crud) - [What are the HTTP methods and where are they used?](#crud-and-http-methods) - [Which HTTP method does each letter in CRUD (Create, Read, Update, Delete) correspond to?](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/#h-use-nouns-instead-of-verbs-in-endpoint-paths) -- [What part of an URL is referred to as the query paramters?](#urls) +- [What part of a URL is referred to as the query parameters?](#urls) - [Which HTTP response status code is used to indicate the permanent relocation of a resource?](#status-codes-300---399-redirection-messages) - [What is an API and how do you make it RESTful](#restful-apis) From efd82ac9fa4f3042c3d8638c584a7083ccf3deba Mon Sep 17 00:00:00 2001 From: Lofty-Brambles <100270817+Lofty-Brambles@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:00:32 +0530 Subject: [PATCH 17/24] fix: wrangling bad grammar Co-authored-by: Asartea <76259120+Asartea@users.noreply.github.com> Co-authored-by: Mayada <115709272+Maddily@users.noreply.github.com> Co-authored-by: Henrique Heron <44820991+autotelico@users.noreply.github.com> --- nodeJS/apis/RESTful_APIs.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 1142bccbabd..518bf0678dc 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -2,7 +2,7 @@ Up until now, you have been creating a server to serve your assets like HTML, CSS, and JavaScript. But you have also learned about React and client-side navigation - here is where we come to understand why. In the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. -This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most glaring benefit of this architecture lies in its separation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app, and a mobile app with the same backend. +This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most obvious benefit of this architecture lies in its separation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app, and a mobile app with the same backend. ### Lesson overview @@ -16,9 +16,9 @@ This section contains a general overview of topics that you will learn in this l ### HTTP -HTTP can be roughly defined as the layer that acts as a protocol for a request-and-response mode of communication between a client (here, browser) and a server. If you open up the network tab in the developer tools of your browser and refresh the page, you will notice a long list of items. These are loosely referred to as "resources" - a thing in the database of your server, that the browser is asking for, as a request, and getting as a response. +HTTP can be roughly defined as the layer that acts as a protocol for a request-and-response mode of communication between a client (here, browser) and a server. If you open up the network tab in the developer tools of your browser and refresh the page, you will notice a long list of items. These are loosely referred to as "resources" - a thing in the database of your server that the browser is asking for as a request and getting as a response. -Clicking on any one of these items will let you see further details about them. Notice that each of these requests and responses has a header and (usually) a body component. The header is responsible for information about the request/response itself, like the address to send/receive from, the kind of information being carried/asked for, and more. The body on the other hand contains the data added to the request/response, like the response to a form or authentication tokens in requests or the page itself in responses. +Clicking on any of these items reveals further details about them. Notice that each request and response has a header and (usually) a body component. The header contains information about the request/response, like the address to send/receive from, the type of information being transmitted, and more. The body contains the data added to the request/response, like form submissions, authentication tokens for requests, or the page content for responses. ### CRUD and HTTP methods @@ -47,7 +47,7 @@ Introduced by the HTTP/1.1 standard, these simply represent that a request was r These tell the client that a request was successfully received and processed. -- `200 OK`: It is the default to indicate a successful request. The result and response depend on the HTTP method, like sending the resource in the body for a `GET` request or describing the created entity for a `POST` request. +200 OK`: This is the default to indicate a successful request. The result and response depend on the HTTP method, like sending the resource in the body for a `GET` request or describing the created entity for a `POST` request. - `202 Accepted`: Indicates that a request was accepted but is being processed. No further context is attached to the response, like whether it will be acted on eventually or not. #### Status codes 300 - 399: Redirection messages @@ -81,7 +81,7 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch ``` - Here, `http` is the protocol. Some others that you might notice include https, ftp, and so on. -- The hostname is `subdomain.domain.com` +- The hostname is `sub.domain.com` - The subdomain here is `sub` - The domain name is `domain.com` - `1234` indicates the port. The browser usually hides this, since it defaults to `80`, which is the default port for web servers. @@ -118,7 +118,7 @@ The following questions are an opportunity to reflect on key topics in this less - [Which HTTP method does each letter in CRUD (Create, Read, Update, Delete) correspond to?](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/#h-use-nouns-instead-of-verbs-in-endpoint-paths) - [What part of a URL is referred to as the query parameters?](#urls) - [Which HTTP response status code is used to indicate the permanent relocation of a resource?](#status-codes-300---399-redirection-messages) -- [What is an API and how do you make it RESTful](#restful-apis) +- [What is an API and how do you make it RESTful?](#restful-apis) ### Additional resources From b3b83c25e8c8165513e9de43abcb394516cff9c7 Mon Sep 17 00:00:00 2001 From: Lofty-Brambles <100270817+Lofty-Brambles@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:03:11 +0530 Subject: [PATCH 18/24] fix: phrasing Co-authored-by: Mayada <115709272+Maddily@users.noreply.github.com> --- nodeJS/apis/RESTful_APIs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 518bf0678dc..bd441a2836a 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -86,7 +86,7 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch - The domain name is `domain.com` - `1234` indicates the port. The browser usually hides this, since it defaults to `80`, which is the default port for web servers. - `/path/to/resource` denotes the resource path which refers to a resource location within the server. -- There are some query parameters here: `?query=something¶m=something`. Query string parameters start with a question mark (`?`), following a `key=value` format and separated by an ampersand (`&`). There can be any number of parameters and they are generally used by the server to spot the right resource. +- There are some query parameters here: `?query=something¶m=something`. Query string parameters start with a question mark (`?`), following a pattern of `key=value` pairs, which are separated by ampersands (`&`). There can be any number of parameters, and they are generally used by the server to identify the right resource. - The `#anchor` is called a fragment or a named anchor. It is used to refer to an internal section within a web document. ### RESTful APIs From 97ee7297f1e3e025807d0ee71844b37a1f9400de Mon Sep 17 00:00:00 2001 From: root Date: Mon, 18 Nov 2024 19:54:18 +0530 Subject: [PATCH 19/24] fix: satisfy markdownlint and URI/URL discrepancy --- nodeJS/apis/RESTful_APIs.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index bd441a2836a..512e5cc1ed3 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -33,7 +33,7 @@ Instead of having a naming convention like `/getPosts` or `/setPosts`, a request | PUT    | Update | `PUT /posts/:postid` - Updates a single post    | | DELETE | Delete | `DELETE /posts/:postid` - Deletes a single post | -There are usually 2 URIs for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URIs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post, or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. +There are usually 2 URLs for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URLs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post, or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. ### HTTP response status codes @@ -47,7 +47,7 @@ Introduced by the HTTP/1.1 standard, these simply represent that a request was r These tell the client that a request was successfully received and processed. -200 OK`: This is the default to indicate a successful request. The result and response depend on the HTTP method, like sending the resource in the body for a `GET` request or describing the created entity for a `POST` request. +- `200 OK`: This is the default to indicate a successful request. The result and response depend on the HTTP method, like sending the resource in the body for a `GET` request or describing the created entity for a `POST` request. - `202 Accepted`: Indicates that a request was accepted but is being processed. No further context is attached to the response, like whether it will be acted on eventually or not. #### Status codes 300 - 399: Redirection messages @@ -93,7 +93,7 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learned in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API, RESTful (adhere to the constraints set by REST). -Since we have already talked about separating the client and the server, it fulfills the first constraint of REST - the two are well-defined as the frontend and the backend. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URIs (Uniform Resource Identifiers) with respect to our resources. +Since we have already talked about separating the client and the server, it fulfills the first constraint of REST - the two are well-defined as the frontend and the backend. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URLs (Uniform Resource Identifiers) with respect to our resources. As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON, primarily due to the ease of parsing it with JavaScript. So all we need to do is to replace our HTML and serve JSON instead. All that you have to do, thus, is to pass your information to [`res.json()`](https://expressjs.com/en/4x/api.html#res.json) instead of [`res.send()`](https://expressjs.com/en/4x/api.html#res.send) or [`res.render()`](https://expressjs.com/en/4x/api.html#res.render). From 2c46d51f4404e31f96e34d354c0cdf6e7a326f2c Mon Sep 17 00:00:00 2001 From: root Date: Mon, 18 Nov 2024 20:09:15 +0530 Subject: [PATCH 20/24] fix: wording around the definition of CRUD --- nodeJS/apis/RESTful_APIs.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 512e5cc1ed3..9ef7c024e03 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -22,7 +22,7 @@ Clicking on any of these items reveals further details about them. Notice that e ### CRUD and HTTP methods -By now you have probably heard about the word CRUD. Broadly, an API is responsible for providing four functions on any resource - **c**reating it, **r**eading about it, **u**pdating it, and **d**eleting it. CRUD describes the actions that you can have on a resource, if your action cannot be described by any of these four, then it could probably be its own model. A key component of any request is to understand what kind of function it wants, amongst these four. +By now, you have probably heard the term CRUD. Broadly, an API provides four functions on any resource - **c**reating it, **r**eading about it, **u**pdating it, and **d**eleting it. CRUD describes the actions you can perform on a resource. If an action doesn't fit into these four categories, it might mean that it should be treated as a separate resource. A key component of any request is understanding which of these four actions it represents. Instead of having a naming convention like `/getPosts` or `/setPosts`, a request directly refers to the resource itself (here, `/posts`) and a corresponding HTTP method (colloquially called HTTP verbs, since they are verbs, grammatically). The methods are as follows: @@ -93,7 +93,7 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learned in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API, RESTful (adhere to the constraints set by REST). -Since we have already talked about separating the client and the server, it fulfills the first constraint of REST - the two are well-defined as the frontend and the backend. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URLs (Uniform Resource Identifiers) with respect to our resources. +Since we have already talked about separating the client and the server, it fulfills the first constraint of REST - the two are well-defined as the frontend and the backend. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URLs with respect to our resources. As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON, primarily due to the ease of parsing it with JavaScript. So all we need to do is to replace our HTML and serve JSON instead. All that you have to do, thus, is to pass your information to [`res.json()`](https://expressjs.com/en/4x/api.html#res.json) instead of [`res.send()`](https://expressjs.com/en/4x/api.html#res.send) or [`res.render()`](https://expressjs.com/en/4x/api.html#res.render). From a5430135af9d543076a2acbb6a73489761289c41 Mon Sep 17 00:00:00 2001 From: Lofty-Brambles <100270817+Lofty-Brambles@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:27:41 +0530 Subject: [PATCH 21/24] fix: more grammar issues Co-authored-by: Mayada <115709272+Maddily@users.noreply.github.com> --- nodeJS/apis/RESTful_APIs.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 9ef7c024e03..0a3bb988a4f 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -33,7 +33,7 @@ Instead of having a naming convention like `/getPosts` or `/setPosts`, a request | PUT    | Update | `PUT /posts/:postid` - Updates a single post    | | DELETE | Delete | `DELETE /posts/:postid` - Deletes a single post | -There are usually 2 URLs for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URLs further is entirely possible, `GET /post/:postid/comments` can get all the comments for a post, or `GET /post/:postid/comments/:commentid` can get a specific comment on a specific post. +There are usually 2 URLs for a resource - one for the entire collection and one for a single object in the collection. One can `GET /posts` for all of the posts or `GET /posts/:postid` for one of them. Nesting URLs further is entirely possible: `GET /posts/:postid/comments` can get all the comments for a post, while `GET /posts/:postid/comments/:commentid` can get a specific comment on a specific post. ### HTTP response status codes @@ -41,7 +41,7 @@ Every response from a server has a response code that provides quick and basic c #### Status codes 100 - 199: Informational responses -Introduced by the HTTP/1.1 standard, these simply represent that a request was received and understood, mostly used on a provisional basis while the request processing continues. It simply alerts the client to wait for a final response. +Introduced by the HTTP/1.1 standard, these indicate that a request was received and understood. They're mostly used on a provisional basis while the request processing continues, alerting the client to wait for a final response. #### Status codes 200 - 299: Successful responses @@ -52,7 +52,7 @@ These tell the client that a request was successfully received and processed. #### Status codes 300 - 399: Redirection messages -Whenever additional action is needed to complete the request, it is indicated to the client with this class of status codes. A major use case for these is URL redirection. +Whenever an additional action is needed to complete the request, it is indicated to the client with this class of status codes. A major use case for these is URL redirection. - `301 Moved Permanently`: Denotes the permanent relocation of any resource to a different URL, while adding the new URL to the response. @@ -67,7 +67,7 @@ These are used to report faults made by the client, like requesting a non-existe #### Status codes 500 - 599: Server error responses -Indicates when the server fails to process a request. +They indicate when the server fails to process a request. - `500 Internal Server Error`: A generic catch-all status code used to indicate an internal error faced by the server while processing the request. - `501 Not Implemented`: The server lacks the capabilities to fulfill the request or is unable to recognize the request method. @@ -91,9 +91,9 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch ### RESTful APIs -Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learned in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API, RESTful (adhere to the constraints set by REST). +Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learned in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API RESTful (adhere to the constraints set by REST). -Since we have already talked about separating the client and the server, it fulfills the first constraint of REST - the two are well-defined as the frontend and the backend. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URLs with respect to our resources. +Earlier, we mentioned separating the client and the server, which fulfills the first constraint of REST: the frontend and backend are well-defined. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URLs with respect to our resources. As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON, primarily due to the ease of parsing it with JavaScript. So all we need to do is to replace our HTML and serve JSON instead. All that you have to do, thus, is to pass your information to [`res.json()`](https://expressjs.com/en/4x/api.html#res.json) instead of [`res.send()`](https://expressjs.com/en/4x/api.html#res.send) or [`res.render()`](https://expressjs.com/en/4x/api.html#res.render). @@ -102,10 +102,10 @@ As mentioned, usually your backend application will need to send data to your fr
1. Check out the [list of HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) listed in the MDN documentation. While you will never use some codes, you will notice a lot of useful ones. -1. Read up on the following resources about REST and RESTful APIs. +1. Read up on REST and RESTful APIs in the following resources.    - Go through the following [CodeAcademy article discussing REST](https://www.codecademy.com/article/what-is-rest). It discusses the definitions of REST and gives some good examples to explain important keywords.    - Check out this [StackOverflow article about RESTful API design](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design). If you want to code along, do remember that the `body-parser` middleware mentioned here has been incorporated into the ExpressJS package itself since 4.16.x and is no longer necessary. -1. Code along with this tutorial on [setting up a REST API with ExpressJS](https://www.robinwieruch.de/node-express-server-rest-api/). Go through this article as thoroughly as possible since it discusses some key details like organization, middlewares, and links some important resources at the end. +1. Code along with this tutorial on [setting up a REST API with ExpressJS](https://www.robinwieruch.de/node-express-server-rest-api/). Go through this article thoroughly, as it covers key details like organizing your code, dive into middlewares, and provides links to other important resources at the end.
@@ -114,10 +114,10 @@ As mentioned, usually your backend application will need to send data to your fr The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge. - [What is CRUD?](https://www.codecademy.com/article/what-is-crud) -- [What are the HTTP methods and where are they used?](#crud-and-http-methods) -- [Which HTTP method does each letter in CRUD (Create, Read, Update, Delete) correspond to?](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/#h-use-nouns-instead-of-verbs-in-endpoint-paths) -- [What part of a URL is referred to as the query parameters?](#urls) -- [Which HTTP response status code is used to indicate the permanent relocation of a resource?](#status-codes-300---399-redirection-messages) +- [What are the four main HTTP methods, and how are they used?](#crud-and-http-methods) +- [Which HTTP method corresponds to each action in CRUD (Create, Read, Update, Delete)?](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/#h-use-nouns-instead-of-verbs-in-endpoint-paths) +- [Which part of a URL is referred to as query parameters?](#urls) +- [Which HTTP response status code indicates the permanent relocation of a resource?](#status-codes-300-399-redirection-messages) - [What is an API and how do you make it RESTful?](#restful-apis) ### Additional resources From 257509263a2eeb571933b31cf7b035e7506467ab Mon Sep 17 00:00:00 2001 From: Lofty_Brambles Date: Fri, 3 Jan 2025 17:35:07 +0000 Subject: [PATCH 22/24] feat: rephrasing the API and introduction sections --- nodeJS/apis/RESTful_APIs.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 0a3bb988a4f..ba52fc71fb1 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -1,8 +1,10 @@ ### Introduction -Up until now, you have been creating a server to serve your assets like HTML, CSS, and JavaScript. But you have also learned about React and client-side navigation - here is where we come to understand why. In the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. +When simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learned in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. Until now, you have been creating a server to serve your assets like HTML, CSS, and JavaScript. But you have also learned about React and client-side navigation - here is where we come to understand why. -This technique is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most obvious benefit of this architecture lies in its separation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app, and a mobile app with the same backend. +In the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. + +This pattern is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most obvious benefit of this is its separation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app, and a mobile app with the same backend. These two seperate entities interact with the help of APIs. ### Lesson overview @@ -91,7 +93,7 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch ### RESTful APIs -Simply put, an API is an interface. When an application needs to interact with another, it sends a request to the respective API. As you've learned in previous lessons, in the context of the web, any server that is created to serve data for external use is called an API. While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API RESTful (adhere to the constraints set by REST). +While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API RESTful (adhere to the constraints set by REST). Earlier, we mentioned separating the client and the server, which fulfills the first constraint of REST: the frontend and backend are well-defined. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URLs with respect to our resources. From 2aa71bb89eda96905233381369a8e5c4cef645ea Mon Sep 17 00:00:00 2001 From: Lofty_Brambles Date: Fri, 3 Jan 2025 17:36:50 +0000 Subject: [PATCH 23/24] fix (introduction): satisfy codespell --- nodeJS/apis/RESTful_APIs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index ba52fc71fb1..6d93e12c3be 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -4,7 +4,7 @@ When simply put, an API is an interface. When an application needs to interact w In the last decade, a specific pattern for developing websites has gained a lot of popularity. Instead of creating an app that hosts both the database and view templates, one can separate these concerns into separate projects, hosting their backend and database on a server (either on something like [Heroku](https://www.heroku.com/) or on a VPS like [Digital Ocean](https://www.digitalocean.com/)), then using a service such as [GitHub Pages](https://pages.github.com/) or [Netlify](https://www.netlify.com/) to host their frontend. -This pattern is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most obvious benefit of this is its separation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app, and a mobile app with the same backend. These two seperate entities interact with the help of APIs. +This pattern is sometimes referred to as the [Jamstack](https://jamstack.org/what-is-jamstack/). The most obvious benefit of this is its separation of the business logic and view logic. This allows you to use a singular backend as a source of data for whatever frontend application(s) you want. You can send data to a website, a desktop app, and a mobile app with the same backend. These two separate entities interact with the help of APIs. ### Lesson overview From 7be3515f0338afcf0814270d1f6b9ce963f1495b Mon Sep 17 00:00:00 2001 From: Lofty_Brambles Date: Thu, 27 Mar 2025 07:29:05 +0000 Subject: [PATCH 24/24] fix: change ExpressJS to Express --- nodeJS/apis/RESTful_APIs.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nodeJS/apis/RESTful_APIs.md b/nodeJS/apis/RESTful_APIs.md index 6d93e12c3be..15bd01a87e2 100644 --- a/nodeJS/apis/RESTful_APIs.md +++ b/nodeJS/apis/RESTful_APIs.md @@ -95,7 +95,7 @@ http://sub.domain.com:1234/path/to/resource?query=something¶m=something#anch While you can structure your API in multiple ways, a popular and conventional method to do so is to follow REST (**Re**presentational **S**tate **T**ransfer). [The exact definition of REST](https://en.wikipedia.org/wiki/REST#Principle) might be a little complicated, but for us, it states that there is a set of standards to be followed to make our API RESTful (adhere to the constraints set by REST). -Earlier, we mentioned separating the client and the server, which fulfills the first constraint of REST: the frontend and backend are well-defined. Further constraints like statelessness and caching are covered by and ensured later with ExpressJS. Our key concern at this point is the organization of endpoint URLs with respect to our resources. +Earlier, we mentioned separating the client and the server, which fulfills the first constraint of REST: the frontend and backend are well-defined. Further constraints like statelessness and caching are covered by and ensured later with Express. Our key concern at this point is the organization of endpoint URLs with respect to our resources. As mentioned, usually your backend application will need to send data to your frontend. The most popular way to do so by far is with JSON, primarily due to the ease of parsing it with JavaScript. So all we need to do is to replace our HTML and serve JSON instead. All that you have to do, thus, is to pass your information to [`res.json()`](https://expressjs.com/en/4x/api.html#res.json) instead of [`res.send()`](https://expressjs.com/en/4x/api.html#res.send) or [`res.render()`](https://expressjs.com/en/4x/api.html#res.render). @@ -106,8 +106,8 @@ As mentioned, usually your backend application will need to send data to your fr 1. Check out the [list of HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) listed in the MDN documentation. While you will never use some codes, you will notice a lot of useful ones. 1. Read up on REST and RESTful APIs in the following resources.    - Go through the following [CodeAcademy article discussing REST](https://www.codecademy.com/article/what-is-rest). It discusses the definitions of REST and gives some good examples to explain important keywords. -   - Check out this [StackOverflow article about RESTful API design](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design). If you want to code along, do remember that the `body-parser` middleware mentioned here has been incorporated into the ExpressJS package itself since 4.16.x and is no longer necessary. -1. Code along with this tutorial on [setting up a REST API with ExpressJS](https://www.robinwieruch.de/node-express-server-rest-api/). Go through this article thoroughly, as it covers key details like organizing your code, dive into middlewares, and provides links to other important resources at the end. +   - Check out this [StackOverflow article about RESTful API design](https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design). If you want to code along, do remember that the `body-parser` middleware mentioned here has been incorporated into the Express package itself since 4.16.x and is no longer necessary. +1. Code along with this tutorial on [setting up a REST API with Express](https://www.robinwieruch.de/node-express-server-rest-api/). Go through this article thoroughly, as it covers key details like organizing your code, dive into middlewares, and provides links to other important resources at the end.