Backend Flashcards

1
Q

Web Framework

A

A software framework designed to support web application development

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Express

A

A minimalist web framework for Node.js. Express abstracts away many difficulties working directly in Node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Node.js

A

Node.js brings event-driven programming to web servers, enabling development of fast web servers in JavaScript. Developers can create scalable servers without using threading, by using a simplified model of event-driven programming that uses callbacks to signal the completion of a task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Middleware

A

A function that an express server runs between receiving a request and responding to that request:

const middleware = (req, res, next) => {
  // Middleware function body
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

(req, res, next)

A

The req parameter stands for request. Information and methods related to the incoming request will be stored in this object.

The res parameter stands for response. This object has information and methods related to sending back a response from the server.

The next parameter, when called, will tell Express that this middleware function is complete. It will then go on to the next piece of middleware.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Route

A

Also called a path, the part of the URL that comes after the domain name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Query String

A

Text that comes at the end of a URL and provides additional information to a given route

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Query Parameter

A

A key-value pair in a query string, used to filter the resources requested from the server. The key and the value are strings separated by an equals sign =. In the below example, the query parameter key is q and the value is javascript.

https://www.google.com/search?q=javascript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Route Parameter

A

A part of the URL that changes depending on the data to be displayed on the website, used to access parts of a URL by storing the value in a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

RESTful APIs

A

A web API that adheres to the constraints of REST (Representational State Transfer - a set of constraints for building web APIs).

With REST, if you have a URL, then you have a resource. Resource refers to the data returned by a request; that data can be a text file, HTML page, image, video, JSON, or something else. Every URL provides access to a resource on your server.

A RESTful API server provides access to resources. A client, like the browser or another server, can then access and change the resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

HTTP Request Method

A

Also called an HTTP verb, a method that indicates the desired action (such as deleting a resource) to be taken on a given resource such as GET, POST, PUT, PATCH, and DELETE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

API Endpoint

A

A location where a client can send a request to retrieve a resource that exists on the server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

HTTP response status code

A

A code sent along with every HTTP response from the server, indicating the server’s response to the client

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

RESTful Design Principles

A

URLs should include nouns, not verbs.
Use plural nouns only for consistency (no singular nouns).
Use HTTP methods (HTTP/1.1) to operate on these resources:
Use HTTP response status codes to represent the outcome of operations on resources.
Should

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

CRUD

A

//(Route name, method, description)

(Create, POST, Create a new post, assign an id, and return at least the id)
(Read, GET, return post/profile with specified id, or return 404 if it doesn’t exist)
(Update, PUT, update an existing post with the data in the request body)
(Delete, DELETE, Delete post with specified id, or return 404 if it doesn’t exist)
(List, GET, Return a list of profiles/posts)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

HTTP Status Codes

A

100 -199: Indicates an informational response; unlikely you will need to return a response in this range
200-299: Indicates success; request was received, understood, and processed.
300-399: Indicates redirection; a resource at a different URL has been subbed for the requested resource
400-499: Indicates a client error; there is a problem with the way the client submitted the request
500-599: Indicates a server error; the request was accepted, but an error on the server prevented request’s fulfillment

17
Q

URL

A

Uniform Resource Locator

18
Q

Controller File

A

A file that defines and exports the route handler functions and is responsible for managing the state of a single resource in an API

19
Q

Express router

A

A modular middleware and routing system that can be attached to an Express app

20
Q

Group-by-resource structure

A

A file organization structure in which any code that handles requests to a resource is stored in a folder with the same name as the resource, regardless of the URL to that resource

21
Q

Database

A

A database is defined as an organized collection of data, generally stored and accessed electronically from a computer system.

Companies rely heavily on databases to store the data that powers their applications. Databases store a variety of data, such as usernames, email addresses, and nearly every other type of information that you can imagine.

Databases reside behind a huge percentage of websites. They’re a crucial component of e-commerce systems, telecommunications systems, banking systems, video games, and just about any other software system or electronic device that maintains some amount of persistent information. They’re also reliable, efficient, and scalable, and these properties make them exceptionally useful and convenient.

22
Q

Hosted database

A

Also called a managed database, a cloud-computing service in which the end user pays a cloud service provider for access to a database

23
Q

Relational database management system

A

RDBMS, a class of programs that can be used to create, update, and administer a relational database

24
Q

Primary key

A

A field that uniquely identifies the records in a table

25
Q

Data definition language

A

DDL, a subset of SQL commands used to define the tables in the database

26
Q

SQL

A

Structured Query Language (SQL) is the database language used to perform operations on a database. You can also use SQL to create a database. SQL uses certain commands, such as CREATE, DROP, and INSERT, to carry out various tasks.

27
Q

One-to-one relationship

A

A relationship where a single record in one table is related to a single record in another table, and neither column has duplicate records

28
Q

One-to-many relationship

A

A relationship where a single record in one table is related to multiple records in another table

29
Q

Many-to-many relationship

A

A relationship where multiple records in one table are related to multiple records in another table

30
Q

Entity Relationship Diagram

A

ERD, a diagram that allows database designers to visualize the tables and the relationships between the tables in a database. ERDs are fairly common because they provide an easy way to communicate to others about a database model that’s being built.

31
Q

Knex Read

A

Service:
function read(postId) {
return knex(“posts”).select(“*”).where({ post_id: postId }).first();
}
———————————————————————————————–
Controller:

async function postExists(req, res, next) {
const { postId } = req.params;

  const post = await service.read(postId);
  if (post) {
    res.locals.post = post;
    return next();
  }
  return next({ status: 404, message: `Post cannot be found.` });
}
function read(req, res) {
  const { post: data } = res.locals;
  res.json({ data });
}

module.exports = {
read: [asyncErrorBoundary(postExists), asyncErrorBoundary(read)],
};
————————————————————————————————————

32
Q

Knex Create

A

Service:

function create(post) {
  //your solution here 
  return knex("posts")
  .insert(post)
  .returning("*")
  .then((createdRecords) => createdRecords[0]);
}
-----------------------------------------------------------------------------
Controller: 
async function create(req, res) {
  // your solution here
const data = await service.create(req.body.data);
  res.status(201).json({data});
}
module.exports = {
  create: asyncErrorBoundary(create),

};

33
Q

Knex Delete

A

Service:
function destroy(postId) {
return knex(“posts as p”).where( {“p.post_id”: postId}).del();
}
—————————————————————————————
Controller:
async function postExists(req, res, next) {
const { postId } = req.params;

  const post = await service.read(postId);
  if (post) {
    res.locals.post = post;
    return next();
  }
  return next({ status: 404, message: `Post cannot be found.` });
}

async function destroy(req, res) {
await service.delete(res.locals.post.post_id);
res.sendStatus(204);
}
module.exports = {
delete: [asyncErrorBoundary(postExists), asyncErrorBoundary(destroy)],
};

34
Q

Knex List

A
Service:
function list() {
  return knex("products").select("*");
}
----------------------------------------------------
Controller:
async function list(req, res, next) {
  const data = await productsService.list();
  res.json({ data });
}
35
Q

Knex Update

A

Service:

function update(updatedPost) {
  return knex("posts as p")
  .select("*")
  .where({ "p.post_id": updatedPost.post_id})
  .update(updatedPost, "*")
  .then((res) => res[0])
}
------------------------------------------------------------------------
Controller:

async function postExists(req, res, next) {
const { postId } = req.params;

  const post = await service.read(postId);
  if (post) {
    res.locals.post = post;
    return next();
  }
  return next({ status: 404, message: `Post cannot be found.` });
}
async function update(req, res) {
  const updatedPost = {
    ...req.body.data,
    post_id: res.locals.post.post_id,
  }
  const data = await service.update(updatedPost)
  res.json({ data });
}

module.exports = {
update: [asyncErrorBoundary(postExists), asyncErrorBoundary(update)],
}