Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Lesson: Basic REST API #29090

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Lofty-Brambles
Copy link
Contributor

@Lofty-Brambles Lofty-Brambles commented Nov 17, 2024

Because

New lesson on Basic REST APIs. Part of Milestone #2 of the Node Revamp.

This PR

  • Adds a fresh lesson as a part of the Node Revamp Milestone #2.

Issue

Closes #28832

Additional Information

The Markdown Preview tool does not render the nested list under assignments and tables properly. The style for those was copied from other, currently active lessons.

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

@github-actions github-actions bot added the Content: NodeJS Involves the NodeJS course label Nov 17, 2024
Copy link
Contributor

@Maddily Maddily left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work overall. I suggested a few minor changes to improve the flow and clarity.

nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
Copy link
Contributor

@autotelico autotelico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went through the article and it's looking great. I've made a few corrections and grammar improvement suggestions.

nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Asartea Asartea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: this lesson uses the term URI 4 times, and URL 9 times. Is there (for the content of this lesson) a meaningful difference expressed with that? Otherwise it should be probably use one of those consistently.

Excluding that and a few minor nits I think overall it looks great

nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Show resolved Hide resolved
Copy link
Contributor

@Maddily Maddily left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a few other small tweaks for readability.

nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
nodeJS/apis/RESTful_APIs.md Outdated Show resolved Hide resolved
Comment on lines +28 to +34

| 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 |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't rendering as expected on the preview tool, can you take a look https://www.theodinproject.com/lessons/preview

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in (TheOdinProject/theodinproject#4858).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has now been fixed

Comment on lines +3 to +5
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 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent introduction, though I feel it is a little vague. What technique, or architecture are we talking about? I think we should mention the term API here so it makes a little more sense to a new learner

Comment on lines +92 to +98
### 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).

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still debating this but what do we think about having this section start the lesson instead of it being in the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to keep this section specifically, here. We use a ton of terms in the linked documentation, like URL and HTTP methods, which should be explained before diving into the express docs with res.json.
What we could do is move the explanation of API and add it in a succinct manner right before 'technique called Jamstack' paragraph and mention the Restful bits here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: NodeJS Involves the NodeJS course
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Lesson: RESTful APIs
6 participants