Introduction to REST methods

Andrew Lu
2 min readFeb 4, 2020

--

Representational State Transfer, known as REST, is a method to access data through CRUD, four basic operations you can do to data.

Coming into web development, REST methods come hand in hand when creating a database. When handling a database, you would want to establish your api routes in your routes folder. An example can be shown below for basic GET POST PUT DELETE using sequelize and mysql. The syntax is only slightly different from mongojs and mongoose, so please alter to your own understanding.

GET POST PUT DELETE

For PUT and DELETE, they are setup in a way where an ID is specified for the target to be updated/deleted. This parameter can be changed to anything within the database, as the api searches first and then does the action.

To call these functions in your javascript using node, here’s another code snippet to show how they can be called and used.

These are simply code to access your pre-established api routes. If you haven’t set up a route, these queries will not work.

A recommended way of using them will be throwing them into functions that passes data as an argument so that they get called when data is available.

A basic example from a personal project can be shown below, this is when I take inputs from a bootstrap form and upon clicking the “add” button, the code below runs and posts:

These are basic ways of using CRUD in a web development environment. Use console.log(data) to explore your data and then parse whatever you need within the object/object array to display onto your server console/webpage.

Any corrections or suggestions on updating this post, please message me in my medium account whenever.

Thanks for reading

--

--

Andrew Lu

Computer Engineering Graduate aspired to make a lot of money