Understand Flask Concepts Flashcards

1
Q

What is an API?

A

An API (Application Programming Interface) is a set of rules and protocols that allow different software applications to communicate with each other. It defines the methods and data formats that applications can use to request and exchange information. In web development, APIs are commonly used to enable interaction between front-end and back-end systems or between different services.

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

What is ReSTful Routing?

A

RESTful routing refers to a design pattern for building APIs that follows the principles of REST (Representational State Transfer). It uses standard HTTP methods (GET, POST, PUT, DELETE, etc.) to perform CRUD (Create, Read, Update, Delete) operations on resources. Each resource is uniquely identified by a URL (Uniform Resource Locator) and interacts with the server through stateless requests.

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

What is serialization?

A

Serialization is the process of converting complex data objects (such as objects in code) into a format that can be easily stored (e.g., JSON, XML) or transmitted over a network. In web development, serialization is often used to convert database query results or Python objects into JSON responses that can be sent to clients.

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

What is the ORM that we use?

A

In the context of Python web development with frameworks like Flask, SQLAlchemy is a popular Object-Relational Mapping (ORM) library used to interact with relational databases. SQLAlchemy allows developers to define database models as Python classes and perform database operations using Python methods, abstracting away the SQL queries.

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

How do we create migrations?

A
  • Making a class a model: Define a Python class that inherits from SQLAlchemy.Model.
  • Creating migration files: Use a migration tool like Alembic (flask db init, flask db migrate, flask db upgrade) to generate migration scripts based on changes in your models.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we complete a SQLAlchemy transaction?

A

For SQLAlchemy transactions (session.commit()):

  • Saving: Use session.add() to add a new object and session.commit() to save it to the database.
  • Updating: Modify the object within a session and then commit the changes using session.commit().
  • Deleting: Use session.delete() to mark an object for deletion and then commit the transaction with session.commit().
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do we use for validations in the client side? (Explain using Formik)

A

In React applications, Formik is a popular library used for handling forms and form validations. It provides utilities to manage form state, validate inputs, handle form submission, and display error messages based on validation rules defined in JavaScript.

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

The two kinds of validations on the backend and how they work (Constraints and the validates decorator)

A
  • Constraints (declarative constraints): Defined directly in the database schema or ORM model (e.g., nullable=False, unique=True). These constraints are enforced at the database level.
  • Validates decorator (imperative validations): Used in SQLAlchemy to define custom validation rules within model classes using the @validates decorator. These validations are performed in Python before database operations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do we implement relationships? (Both one to many and many to many)

A
  • One-to-Many relationship: Define a foreign key in the child table (many side) that references the primary key in the parent table (one side).
  • Many-to-Many relationship: Use an association table (secondary table) that links two tables through foreign keys, where each record in the association table represents a relationship between instances of the other two tables.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Request / Response Cycle from a GET Request or POST from a Form

A
  • GET Request:
    1. Client sends a GET request to the server.
    2. Server receives the request, processes it, and retrieves the requested data.
    3. Server sends a response containing the requested data (typically in JSON, HTML, or other formats).
    4. Client receives the response and processes/display the data.
  • POST from a Form:
    1. Client submits a form with data using a POST request to the server.
    2. Server receives the POST request and processes the form data.
    3. Server performs necessary actions (e.g., storing data in a database, updating records).
    4. Server sends a response back to the client indicating the success or failure of the operation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly