...Penney Garrett...

Oh Crud!

Well if I've learned anything in these months of web development school, it's that this stuff is harder than I anticipated. In the interest of helping all these difficult concepts sink in a bit better, I am going to try to revisit and write about some of them.


Today's topic? CRUD!


Ewww, what's CRUD? That doesn't sound like something you want anywhere near your computer! CRUD stands for Create, Read (or sometimes Retrieve), Update, and Destroy. These are the four basic functions of persistant storage. CRUD provides everything we need to manage the flow of data through and within a database. Differest users interacting with a database may have different CRUD cycles based on their authorizations - for example, a regular user may not be able to delete or update anything on a website, whereas an administrator would.


So what does this look like in practice?


Well to illustrate how CRUD works in practice it will first be helpful to explain a bit about what HTTP verbs are. HTTP stands for Hypertext Transfer Protocol - it is the protocol to exchange or transfer hypertext on the web. HTTP functions as a request/response cycle between a client and server. The client (for example, a web browser) initiates a request to the server, which in turn processes that request and sends a response back. Within the information that gets passed along with the initial request is a verb which indicates the desired action to be performed. The main HTTP verbs are GET, POST, PUT or PATCH, and DELETE. Roughly simplified they mean:



So now back to the CRUD! Using HTTP verbs we can work through the Create, Read, Update, and Delete cycle. Let's pretend we have a website for records (as in vinyl records that play music). Our verbs and CRUD give us 7 combinations:


HTTP Verb/Method URL/Action Part of CRUD Gives us:
GET "/records" READ Here we can see all of our records
GET "/records/:id" READ Here we see an individual record
GET "/records/new" CREATE (part 1) We get a form to put in information for a new record
POST "/records" CREATE (part 2) That new record gets created
GET "/records/:id/edit" UPDATE (part 1) A form to edit a record
PUT/PATCH "/records/:id" UPDATE (part 2) That record is updated
DELETE "/records/:id" DELETE A record is deleted

And that's it! You now know the basic framework for most websites!



<----