Quiz
- I think I'm just still a little confused on how all these are related to each other.
Who could blame you? We've already seen one summary; let's try another:
- JS running in the browser can initiate requests.
- GET and POST are just like usual, but we also have PUT and DELETE.
- The back end can respond with JSON instead of a web page
- JS running in the browser can receive the response and (optionally) update the page.
- Often GET/POST/PUT/DELETE are used in a particular way called a REST API.
- Do POST and GET in ajax work the same way as methods in HTML forms?
Yes. Well, the request is the same, but the response is different
- are there any examples from past projects that used ajax?
A lot of people end up creating "like" buttons; that's a good use of Ajax. Sometimes they even do comments and such.
- Can you talk more about APIs work?
There are two answers here. One general and one more specific.
In general, an API (application program interface) is how one program talks to another.
For example, we can talk about the
bcrypt
API, which consists of just two functions:gensalt
andhashpw
. Or theFlask
API, which is much more complicated.In the context of this reading, an API is a set of endpoints and HTTP methods that allow a front-end (usually a browser, but might be another program) to talk to a back-end (a web server).
- How do we switch between Javascript and HTML code? Can we go over the REST API example again?
The HTML
<script>
allows you to embed JS code in an HTML page, or to load JS code from an external file.I'm happy to go over the REST API
- Can you please go over the person app providing the rest api code?
Sure. Here's the link to the people app