CRUD APIs & Express (Class 37-38) Flashcards
What is internet?
A wire connecting client side and server side.
Browser running on client side sends a request to server, server heard our request (through lines of codes, known as API) and respond back
When you type in url and enter, what happens?
You are making a get request to a server, and we can code our server to hear that request and to know what to do when it hears it.
What is CRUD?
Create (post) - Make something
Read (get) - Get something
Update (put) - Change something
Delete (delete) - Remove something
Using instagram as an example, what are some Create (post) requests?
Making a new post on instagram (I am sending data to a server and the server use the data to make a new post)
Using instagram as an example, what are some Read (get) requests?
Scrolling through your feed or looking at individual post of your friend (I am asking server to get me the data)
Using instagram as an example, what are some Update (put) requests?
Editing a comment or click the like (or love) icons (If my like goes from 0 to 1, I am updating something on the server)
Using instagram as an example, what are some Delete (delete) requests?
Deleting a post
In the browser, if i type instagram.com, what type of request is client making?
Get (Read) request
When I like the photo on instagram, what kind of a request is client making?
Put (Update) request
and lines of code (API) in the server hears the request and respond back
Why requires 2 steps for liking the instagram post?
- Client send put request (Update) when liking a photo (to update data)
- Server updated the data and refresh the page (refreshing trigger a new GET request and send new updated HTML)
Same is true with delete request
When I create a new post on instagram, what kind of a request is client making?
- Client sending Post (Create) request
- API in the server hears the request and respond by creating a new post for client
- When everything went ok, browser will refresh and send Read (Get) request and display a new post
What is Express?
Fast, un-opinionated, minimalist web framework for Node.js.
With a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy
What is middleware?
A lot of stuff happens in between a request coming in and response going out. All the tools and things that help the process between the request and response
What is express (in simple terms)?
Web framework for node.js (can only be used with node.js)
(just like django for python, ruby on rails for Ruby, etc)
Key steps before building
mkdir api-project
cd api-project
npm init
npm install express –save