-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
base: main
Are you sure you want to change the base?
New Lesson: Basic REST API #29090
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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
Co-authored-by: Asartea <[email protected]> Co-authored-by: Mayada <[email protected]> Co-authored-by: Henrique Heron <[email protected]>
Co-authored-by: Mayada <[email protected]>
There was a problem hiding this 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.
Co-authored-by: Mayada <[email protected]>
|
||
| 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 was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has now been fixed
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. |
There was a problem hiding this comment.
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
### 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). |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Because
New lesson on Basic REST APIs. Part of Milestone
#2
of the Node Revamp.This PR
#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
location of change: brief description of change
format, e.g.Intro to HTML and CSS lesson: Fix link text
Because
section summarizes the reason for this PRThis PR
section has a bullet point list describing the changes in this PRIssue
section