Fullstack Stack Part 2 Flashcards
What’s the difference between a library and a framework
People use these terms interchangeably but they don’t mean the same thing. Frameworks and libraries are both code written by someone else that helps you perform some common tasks in a less verbose way
LIBRARY:
- Using a library = going to Ikea to pick items you need
- You are in control of when are where you call the library (like jquery)
FRAMEWORK:
- Using a framework = moving into a model home that has everything decorated for you already
- Frameworks are more opinionated
- When you use a framework, the framework is in charge of the flow and provides some places for you to plug in your code (as needed)
Express
- Express is the most popular Node web framework and is the underlying library for many other popular Node Web Framework
- As a framework, express is mostly unopinionated
- The Express library provides mechanisms to:
o Write handlers for requests with different HTTP verbs at different URL paths (routes)
o Add request processing middleware at any point in the request handling pipeline - Express itself is fairly minimalist, but is compatible with other libraries that work with cookies, sessions, URL parameters (for example Express body-parser
Express Router
We can create a router with express.Router(). The Express Router is like a mini express application and it provides us with useful routing APIs like .use , . get , . param . We can have many routers for different types of routes, which in turn makes our applications more modular and flexible.
Routing
Routing refers to how an applications endpoint’s respond to client requests. Each route can have one or more handler functions that get executed when the route is matched.
app. METHOD(PATH, HANDLER)
- app is an instance of express
- Method is an http request method
- Path is a path on the server
- Handler is the callback function executed when the route is matched
HTTP
Hyper Text Transfer Protocol
A client-server protocol which allows the fetching of resources like HTML documents
Clients and servers communicate by exchanging individual messages (1 Request, 1 Response)
It is the foundation of any data exchange on the web
API
- Application Programming Interface
- An API allows two systems to communicate with one another and provides the language and contract for how these systems can interact
- API’s can use HTTP requests to get information from a web application or web server
- when a company offers an API to their customers, it just means that they’ve built a set of dedicated URLs that return pure data responses
API Endpoint
- An endpoint is one end of a communication channel. When an API interacts with another system, the touchpoints of the communication are considered endpoints.
- Each endpoint is the location from which APIs can access the resources they need to carry out their functions.
- Endpoints specify where resources can be accessed by APIs.
Route Parameters
Named URL segments that are used to capture the values specified at their position in the URL. The captured values are populated in the req.params object
Example: http://www.cookies.com/:cookieId
RESTful Routing
Representational State Transfer – an architectural style for designing backend applications.
Restful routes are a conventional pattern to follow when structuring different routes for interacting with the server whenever an HTTP request is made.
In order for a route to be completely RESTful, it must:
- Separate the client from the server
- Be reliable
- Use HTTP verbs and URLs
- Not hold state between requests (all information necessary to respond to a request is available in each request)
Express Body Parser
Express comes with a built-in middleware that automatically parses incoming request bodies and makes the data available under req.body
Express Middleware
- A function that receives the request and response objects of an HTTP request/response cycle.
- Middleware can execute any code (like logging) and then move to the next middleware on the chain or modify the request and response objects before passing them on to the next middleware on the chain.
- Middleware can also end the request/response cycle (res.send)
Client vs. server
The client connects to the server to ask it to perform actions. The client sends HTTP requests. The client is often the browser.
The server is a connection point for several clients that will handle their requests. It responds to HTTP requests
Request / Response Cycle
ONE REQUEST – ONE RESPONSE
- Request: a formatted message sent over the network by a client. Consists of VERB, URI (route), headers, and body
- Response: A server’s reply to a request. Contains headers, status
Payload
A payload is the actual data pack that is sent with the GET method in HTTP. It’s the part of the transmitted data that holds the actual intended message
It is crucial information that you submit to the server when you are making an API request. It’s oftentimes a JSON Object
JSON
JavaScript Object Notation
Lightweight, data-interchangeable format
Data is stored in name / value pairs that are in quotes
DBMS
Database Management System
A DBMS doesn’t have to be relational. It’s just an application that intelligently stores data and can answer requests that manage the data. A DBMS is a one layer and language to store and access data – sold as a way for non-technical people to manage data.
RDBMS
Relational Database Management System – allows you to create, update, and administer a relational database. Most RDBMS use SQL to access the database.
SQL
Structured Query Language = a programming language used to communicate with data stored in a relational database management system.
MySQL
MySQL is a relational database management system based on SQL
Database
A database persists information and is accessible via code.
Good databases are:
- Organized
- Queryable
- Manageable
- give us concurrency – multiple clients can make queries to read and update without the risk of deadlock or starvation.
ACID (databases)
Acid refers to a standard set of properties that guarantee database transactions are processed reliably.
A -
Atomicity – you guarantee that either all of the transaction succeeds or none of it does. You don’t get partially successful transactions.
C-
Consistency – Ensures that data is consistent – all data will be valid according to defined rules
I -
Isolation – Guarantees that no transaction will be affected by other transactions that have not yet been completed
D
Durability – Once a transaction is committed, it will remain in the system. Changes must be stored permanently.
PostgreSQL
An advanced, open source relational database that supports both SQL (relational) and JSON (nonrelational) querying.
We commonly call it just “Postgres”
It is NoSQL (Not only SQL)
Postico
Postico provides an easy-to-use interface that makes PostgreSQL more accessible.
Object Relational Mapper (ORM)
Acts as a bridge between our code and the RDBMS.
Object relational mappers let us interact with our database using a language of our choice instead of SQL.
This is great because SQL can be complicated. However, the abstraction means that we won’t have as good of an understanding of what is going on under the hood.
Sequelize
- Sequelize is promised-based Node.js ORM (Object-Relational-Mapper)
- allows us to easily manage a SQL database.
- It maps an object syntax onto our database schemas.
- Sequelize uses a constructor function to connect to your database and it return a Sequelize instance for you to interact with.