Learning Library

← Back to Library

REST API Basics and Benefits

Key Points

  • A REST API (Representational State Transfer) is a standardized, stateless architecture that enables client‑server communication via web‑based endpoints.
  • Its main benefits are simplicity and uniform data formatting, scalability without maintaining session state, and high performance through built‑in caching support.
  • In practice, a REST API is accessed through URLs that identify resources (e.g., `icecream.com/api/flavors`), with the client sending requests and the server returning responses.
  • Operations on these resources follow the CRUD model (Create, Read, Update, Delete), mapping to HTTP verbs like POST, GET, PUT, and DELETE.

Full Transcript

# REST API Basics and Benefits **Source:** [https://www.youtube.com/watch?v=lsMQRaeKNDk](https://www.youtube.com/watch?v=lsMQRaeKNDk) **Duration:** 00:09:11 ## Summary - A REST API (Representational State Transfer) is a standardized, stateless architecture that enables client‑server communication via web‑based endpoints. - Its main benefits are simplicity and uniform data formatting, scalability without maintaining session state, and high performance through built‑in caching support. - In practice, a REST API is accessed through URLs that identify resources (e.g., `icecream.com/api/flavors`), with the client sending requests and the server returning responses. - Operations on these resources follow the CRUD model (Create, Read, Update, Delete), mapping to HTTP verbs like POST, GET, PUT, and DELETE. ## Sections - [00:00:00](https://www.youtube.com/watch?v=lsMQRaeKNDk&t=0s) **REST APIs Explained with Ice Cream Example** - The speaker defines REST (Representational State Transfer), explains its role as a standardized client‑server communication method, outlines its benefits, and illustrates its use through a simple ice‑cream‑shop web app scenario. - [00:03:18](https://www.youtube.com/watch?v=lsMQRaeKNDk&t=198s) **Understanding REST API Basics** - The speaker explains API endpoint components, the role of resources, request/response structure, and maps CRUD operations to their corresponding HTTP methods. - [00:06:26](https://www.youtube.com/watch?v=lsMQRaeKNDk&t=386s) **Managing Ice Cream Flavors via REST** - The speaker explains how to retrieve, update, and add ice‑cream flavors using GET, PUT, and POST requests to the /api/flavors endpoint. ## Full Transcript
0:00What is a REST API? 0:01What are the benefits 0:03- and how are they fundamental to your cloud application development? 0:06I'm Nathan Heckman from IBM Cloud, 0:08and I'm going to answer that for you today, 0:10but before i do please hit that subscribe button. 0:14Let's jump in with an example. 0:16Let's say that you work for an ice cream shop 0:18and you're trying to build a web application 0:21to show the flavors of ice cream that are in stock that day 0:25and allow the workers to actually make updates to those flavors. 0:28How do you do this? 0:29Well, with a REST API. 0:31You have your web app or web page communicate with a cloud-based server 0:38via a REST API. Great! 0:43So, let's jump into what exactly a REST API is. 0:48Starting out with: what does "REST" stand for? 0:54So, REST stands for Representational State Transfer. 1:05So it's "REST". 1:08Those words might not mean a whole lot to you 1:11but, basically, it's a standardized software architecture style, 1:14a specific type of API that's industry known and used. 1:19So, the first thing that you should really know about  REST APIs 1:23is they're all about communication. 1:25So, client with server and vice versa - that's how they talk, 1:30and also you may have heard the term "restful". 1:36So, "restful web service", right, that's a service that uses REST APIs to communicate. 1:45So, what are some of the benefits of REST APIs? 1:48First of all, they're a simple and standardized approach to communication. 1:57You don't have to worry about how to format your data, 2:01or how to format your request each time - 2:05it's all standardized and industry used. 2:08Second of all, REST APIs are scalable and stateless. 2:17So, as your service grows in complexity you can easily make modifications 2:23and just the fact that they're stateless means you don't have to worry about 2:26what data is in which state and keep track of that across client and server. 2:30It's truly stateless. 2:33Great, and then finally 2:35they have high performance 2:40in large part due to the fact that they support caching. 2:43So, that's all all good stuff - as your service gets more complex 2:46the performance stays very high. 2:49Great! So, let's go back to our example. 2:51So, for the ice cream shop, what would the REST API look like? 2:57So, you have an endpoint which might look something like this: 3:04"icecream.com/api/flavors" 3:16Right? So, let's break that apart a bit. 3:18So, "api" this just signifies that this is the API portion of the endpoint. 3:23Right? So, pretty straightforward there. 3:25"Flavors" is actually what's known as a "resource". 3:30So, this signifies that we're working with the flavors resource in this this REST API. 3:35Great! 3:37So, in our example, 3:40the main building blocks, or parts, of the REST API are: 3:46the "request", that is sent from the client to the server, 3:53and the "response", that is received back from the the server. 4:00So, let's let's break those apart a little bit. 4:03Over here, let's put a big old box for request, 4:10and what are the type of things that you might want to do with a REST API? 4:13What actions or verbs would you want to make when you're working with one? 4:18You may have heard of "CRUD" - what does CRUD stand for? 4:25So, CRUD is "Create, Read, Update, and Delete". 4:36These are some of the main things that you might want to do 4:38when you're communicating with your client and server. 4:40On a REST API, the equivalent of those are are actually HTTP "methods" 4:48or "operations". 4:53So, what's the equivalent of "create" in an HTTP method? 4:57Well, it's "post". 5:00And how about "read"? 5:02So, read is actually called "get". 5:05Update or replace is "put", 5:09... and delete? Guess what it is: "delete". 5:14Not too creative there. 5:16So, how about a request itself? 5:18What are some of the pieces of it? 5:20So, first of all, you might have an operation, 5:24that's kind of what we just talked about here with the HTTP methods, 5:28you might have an endpoint, 5:31which is what we just talked about over here - 5:34this is your REST API endpoint, 5:37and then you might also have parameters or body, 5:46which is some data that you might send in the request, 5:48and we'll see some examples in a moment, 5:50and finally are the headers. 5:56So, this is a special part of an REST API request 6:01which might have things like an API key or some authentication data. 6:05Great - and then, in return, from the server, you'll receive a response, right? 6:11So, we'll put a nice box here for response 6:16and this is typically in the form of JSON data. 6:19Great, so let's jump into our example, 6:21and let's look at a few different scenarios that might happen with your ice cream shop, right? 6:26So, first of all, 6:27let's say that you want to display what's currently in stock, right? 6:32So, we want to get the flavors that are in stock. 6:36So, what does our rest API request look like? 6:39Well, you have a "get" as the operation, 6:42because you're actually wanting to get those flavors, 6:45and then the end point is "/api/flavors", 6:49and, in response, you'll get an array of those flavor resources, right? 6:54So, we see strawberries in stock, as well as mint chocolate ... yummy! 6:59but then, uh oh, mint chocolate is so popular 7:03that it actually runs out for the day, 7:05and the store is scrambling and they want to replace that flavor with another one. 7:10They choose chocolate. Which is a great choice! 7:13So, let's say they want to update the flavors, right? 7:20So, you want to update or replace that mint chocolate with just chocolate. 7:25So, what does our request look like? 7:27It's a "put" operation, so that updates or replaces. 7:31The end point is "/api/flavors/1" to indicate the the ID of "1" you want to replace 7:39and then parameter body you actually specify  the flavor of chocolate, 7:42which is going to be the new flavor that's replaced. 7:45And, in response, we see indeed acknowledging that the ID of "1" 7:49is replaced with a flavor of chocolate. Great! 7:54Good news: the store just received a shipment of a brand new experimental flavor 8:01called "restful raspberry", 8:03and you want to actually load this new ice cream up into your website, right? 8:08So, we want to create a new flavor. 8:15How do we do that with the REST API? 8:17Well, in our operation it's a "post" operation, 8:22so that actually will create a new flavor, 8:24the endpoint is once again "/api/flavors", 8:28and we included in the body the flavor that we want to create, 8:32which is "restful raspberry", 8:34and in response we see ... yep, this new ID of "2" was created, 8:38the flavor is restful raspberry. 8:41Great! So, hopefully this clarifies what exactly is a  REST API? 8:45What are some of the benefits? What's a real world example look like? 8:49... and how are REST APIs fundamental to your cloud application development? 8:55Thank you. 8:56If you have questions please drop us a line below. 8:58If you want to see more videos like this in the future please "like" and subscribe, 9:02- and don't forget: 9:04you can grow your skills and earn a badge with IBM Cloud labs, 9:07which are free browser-based interactive Kubernetes labs.