From the course: Programming Foundations: APIs and Web Services

REST overview

From the course: Programming Foundations: APIs and Web Services

Start my 1-month free trial

REST overview

- You may have heard the term RESTful API and wondered what that meant. REST stands for Representational State Transfer. It's a set of guidelines application developers use to design APIs. To better understand how a RESTful API works between the client and the server, let's use an example. Jane is hungry and sits down in a restaurant. This represents a need. She needs food. Then Jane reviews the menu, which lists all the options she can order. The menu is the API. APIs have a bunch of options you can order and use. Now Jane selects her order, she wants Chicken Parmesan, and tells the waiter. Ordering is the API call. It's sending the message of what the client wants to happen. The kitchen then cooks the food. This is the API doing the work or retrieving the needed data. Finally, the waiter delivers the food to Jane. This is the API response back to the client. She gets what she ordered. Now there are four principles that APIs follow, and let's go over each one. As you use APIs, you will find that these principles will make your life easier. First, data and functionality in the API are considered resources and identified through something called the URI, or Uniform Resource Identifier. These are accessed by web links. Second, resources re manipulated using a fixed set of operations. GET retrieves a resource, POST creates one, use PUT to update the resource, and of course, DELETE will remove it. Third, resources can be represented in multiple formats, like HTML, XML, plain text, and other formats defined by a media type. Finally, communication between the client and endpoint is stateless, meaning the server will not remember or store any state about the client that made the call. To better explain how stateless principles work, let's say you're in line at your local coffee shop and you order your favorite chai tea latte. After you pay and pick up your drink, you remember that you format to order one for your friend. So you get back in line and tell the cashier that you'd like another one. The cashier doesn't remember your order, and you have to tell her your request again. In fact, she's probably serving so many customers, it is impossible for her to remember everything that everyone orders. Web services are the same way. These principles make sure your RESTful applications are simple, lightweight, and fast.

Contents