The Almighty CRUD
Tags: crud, flatironschool, webdev, beginners
Published: 2022-09-05 19:27:40

Since I've completed my second phase of schoolwork at [Flatiron School](flatironschool.com), I thought I should re-visit and explore an important concept which I've been using during this phase. This phase at Flatiron School we predominately focused on the React programming language. During these studies, CRUD and its methods was also a readily utilized topic. It's also one which deserves more exploring. Below I will elaborate on what CRUD is, and how we've interacted with it within almost every React lab we did this phase. 

An important concept in the web developers' world is **CRUD**, which stands for **C**reate, **R**ead, **U**pdate and **D**elete. Each letter in this acronym is an important way of viewing, searching, or changing information using computer-based forms and reports. A web developer would want to pay attention to **CRUD** and **REST** while going to make network requests via an API. In this phase at Flatiron we used many principles found in CRUD to make **REST**ful API requests to both local and remote servers. 

**REST** is an acronym for **RE**presentational **S**tate **T**ransfer and an architectural style for distributed hypermedia systems. It was first presented in in 2000 during Roy Fielding's famous dissertation. REST APIs communicate via HTTP requests to perform standard database functions like creating, reading, updating, and deleting records (CRUD) within a resource. For example, a REST API would use a GET request to retrieve a record, a POST request to create one, a PUT request to update a record, and a DELETE request to delete one.

For the acronym, **C.R.U.D.**, we can elaborate a little more about what each letter means. 

**C** is for Create. The create function allows users to create a new record in the database. In the SQL relational database application, the Create function is called INSERT. SQL (Structured Query Language) is a programming language used to communicate with data stored in a relational database management system. SQL syntax is similar to the English language, which makes it relatively easy to write, read, and interpret. When making RESTful API requests, the name of the request is POST. It creates a new insertion in the database info. 


**R** is for Read. The read function is similar to a search function. It allows users to search and retrieve specific records in the database and read their values. Users may be able to find desired records using keywords, or by filtering the data based on customized criteria. When making API requests, the type of request that corresponds to 'Read' is 'GET.' 

**U** is for Update. The update function is used to modify existing records that exist in the database. To fully change a record, users may have to modify information in multiple fields. In RESTful API methods, the Update of CRUD corresponds to PATCH and PUT. 

**D** is for Delete. The delete function allows users to remove records from a database that are no longer needed. In a RESTful API scenario, the method we use to Delete the records from the server is DELETE. Fancy that!


As I worked through the second phase of Software Engineering cirriculum at Flatiron School, CRUD was a topic that students needed to know of for many reasons. There are many required operations in labs which can use the RESTful CRUD methods. In lab work, when we would update state in our react labs we had to make a corresponding fetch request to persist that change to an API. API means Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. For the labs, we were trying to get our React application, to carry out CRUD requests that would alter data both remotely, and locally from our json-server.

To persist our stateful changes to the 'backend' server, we made fetch requests for each type, **c, r, u,** and **d.** Below are some examples of how CRUD was used in our lessons for Flatiron School.

The following POST request **C**reates new information to be written to the server: 

![CREATE](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nx1g86q7ruxmshmvgn3p.png)


In the following GET request we used, information is **R**ead from the server:

![READ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bottof7cznkzrgii8mdi.png)


The following PATCH request **U**pdates information in the server:

![UPDATE](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0e9lbdbkldqvpumg9y4a.png)


And, the following DELETE request **D**eletes information from the server:

![DELETE](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4aaxd4setzt4jeey1plu.png)

Each type of API request we made had a different mode, each corresponding to one of the **CRUD** methods. By using these methods we were readily able to successfully Create, Read, Update, and Delete information from our server, and persist changes. 

Betwixt all these requests back and forth from our json-server, there was much interaction with the React programming language, which kept the program's internal state up to date with all the information the server had stored. 

CRUD really was an important part of my labs and development of knowledge during this phase at Flatiron. Without the CRUD methods, and their use, much of the programming involved with React would have been inoperable. All of this and more was a big part of what I had learned in Phase 2 at [Flatiron School.](https://flatironschool.com/)