DEV Community

jaredsurya
jaredsurya

Posted on

The Almighty CRUD

Since I've completed my second phase of schoolwork at Flatiron School, 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 Create, Read, Update and Delete. 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 RESTful API requests to both local and remote servers.

REST is an acronym for REpresentational State Transfer 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 Creates new information to be written to the server:

CREATE

In the following GET request we used, information is Read from the server:

READ

The following PATCH request Updates information in the server:

UPDATE

And, the following DELETE request Deletes information from the server:

DELETE

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.

Top comments (0)