LongCut logo

A Beginner's Guide to REST APIs in Under 10 Minutes!

By Cloudmancer

Summary

Topics Covered

  • APIs Are Restaurant Waiters
  • URL Anatomy Reveals Endpoints
  • Match HTTP Methods Precisely
  • API-First Drives Monetization

Full Transcript

apis are everywhere powering the apps that we use every single day but have you ever wondered what's really going on behind the scenes in this video we're breaking down the anatomy of AR rest API showing exactly how they work what makes

them so powerful and why understanding them is the key to building modern software hi if you're new around here my name is Ryan I'm an AWS certified Solutions architect and developer and my goal is to teach you modern serverless

system design using AWS let's dive in all right so this is the anatomy of a rest API a beginner's guide to understanding how apis work the purp purp of this video is to give an

overview of what an API is how it works and some general definitions of some of the nomenclature surrounding apis so we'll go over an analogy to help you better understand how an API works we'll

break down the anatomy of a URL and of an endpoint and then we'll talk about like methods and making requests and receiving responses all right what is an API well an API is an acronym that

stands for application programming interface apis offer a way to standardize communication between software applications with a set of rules and protocols it defines methods

and data formats that applications can use to request and receive information enabling them to interact and perform specific functions apis act as intermediaries allowing developers to

access the functionality of other software systems without needing to understand how those underlying systems work this simplifies integration and enhances efficiency in development processes though there are many

different kinds of apis when somebody says API they are usually referring to a rest API and that's going to be the focus of this video so apis can be best

understood as a restaurant a patron or a client in API terms enters a restaurant and sits at a table with the intention of ordering food the patron knows that the food is kept in the kitchen or the server but is not able to go get that

food himself nor is he a very good cook so how does the patron get the food that he wants enter the waiter or the API the waiter listens to the Patron's order or request and then delivers that order to

the kitchen the kitchen then makes the food or the response hands it to the waiter and then the waiter delivers it to the patron so you can use this analogy to help you visualize how rest apis work at their core so let's talk

about how it works first an API is called when a client invokes a URL with a specified endpoint and Method a client can be a front-end web application a user a backend really anything they can

communicate over hypertext transfer protocol or HTTP a URL is a uniform resource locator and it's used to locate specific things on the internet an endpoint specifies which data the client

is looking for from the server and the method indicates the intention of the request whether or not the client wants to read or write data these things together make up the request a request can contain headers parameters or a

payload and we'll talk about more of these here in a little bit when a request is successfully sent the server will send back a response the response doesn't always have to be a successful one it can also be an error a response

will generally include a status code that indicates whether the request was successful or not it will also include headers as well as a response body that includes the data that was requested so let's break down the anatomy of a

uniform resource locator or URL a URL is comprised of many different pieces the first being the top level domain in this case which is and the second level domain which is Google and these

together comprise the root level domain in addition to the root level domain you will have the protocol which in this case is https some URLs also include a subdomain in this case www but this can

be anything that occurs before the second level domain and after after the colon SL slash the final part of the URL is the endpoint and this is the specific place in the root level domain that you

wish to navigate to if you combine all of these pieces together other than the protocol you get the fully qualified domain name this is the exact location of a place that you wish to navigate to on the internet so let's talk about how

you make a request in a rest API a request is an outbound call made from a client to an endpoint requesting some sort of data or to perform some kind of function making a request is the first

step in the client server communication process a request includes headers headers contain various metadata some of it essential for the request headers can include the type of content being sent

authorization keys or tokens or the encoding that's used a request is always sent with a method a method indicates the desired action category that a client wants the server to execute and

whether the client intends on reading or writing data the method of the request will dictate which of the following data is sent the payload is a Json object with additional data path parameters are

variable included in the URL path and query string parameters are appended to the end of the URL to filter data so let's talk a little bit about methods choosing the correct method when making a request is imperative the same

endpoint can have very different requirements depending on the method of the request a get is a method used to fetch data without modifying any resources an example would be retrieving

a list of users a post method is used to create new resources for example adding a user to the database a put is used to update an entire resource this would be updating all of a user's details whereas

a patch is used for updating a partial piece of a resource for example changing just a user's email address and finally delete is used to delete a resource this would be like deleting a user completely

from the system any request contains headers and they can also contain path or query string parameters postp put or patch methods usually also include a payload object that contains information

about what is to be created or updated let's take a look at a couple of example endpoints and what they might look like depending on the method that you're using in the request so let's say you wanted to update some information about

an existing user this could be an example of what the endpoint might look like it contains a path parameter of the user ID which would reference the user that we want to update the method we would use might be a put method and in

that put request we would probably have a payload object that would include all of the information about that user that we wanted to update let's take a look at a little bit more complex example so I know this looks like a lot but let's break this down a little bit in this

request we're querying for a specific group ID in our path parameter but then we also have some query string parameters here attached onto the end in query string parameters it's always going to start with a question mark and

then following the question mark it will contain a list of key value pairs with an Amper sand as the delimiter between those key and value pairs in this case we're going to query A specific group ID

and then the query string parameters dictate that we will filter that data based on only returning active users whose first name equals Ryan in this case the method would most be a get

method so let's talk about what a response might look like from an API call all client requests that are successfully received by the server will return a response a response will generally include some headers a status

code that indicates whether it was a successful or a failed response and hopefully a body object if it was successful the body will include the requested data or the error if it was unsuccessful usually you'll get this

response in Json format wrong Json and you can see here what an example of that would look like with a status code some different headers and then our body object of the

requested data 200 level status codes generally indicate that the request was successful while 400 and 500 status codes will indicate an error 400 status codes generally indicating an error with

the client request while 500 status codes will generally indicate an error with the server now that you know a little bit about the basics of rest apis let's talk a little bit about why that's important again apis are just an

interface that allow internal and external developers to access a systems resources more and more organizations are developing an API first approach what this means is that the apis and

their structure are designed and developed sometimes even before the application itself which ensures better integration and scalability this allows organizations to standardize the way

that their data and services are interacted with and also opens up a path to monetization by allowing thirdparty developers to access those apis apis offer an enhanced developer experience

for anyone who wants to build applications tools platforms that streamline API design testing and documentation will become more sophisticated but they will also provide a more seamless experience for

developers apis are also secure while a deep dive on API security is outside of the scope of this video they will be increasingly designed with zero trust principles which will ensure robust

security measures such as continuous authentication and authorization also a lot of businesses are making the move towards Cloud first and microservice architectures apis are an integral part

of microservice AR architectures as they facilitate the communication between Loosely coupled components and finally standardization efforts to standardize API practices and protocols will gain

momentum this will help to make apis more consistent and interoperable between different platforms and industries I have some additional resources and reading here but I'll include this PowerPoint as well as all of these resources down in the

description that about wraps up the video for today I'm curious to hear your experience with apis and I'm also curious to hear where you think apis are going in the future if there's any other videos that you want to see me make please let me know down in the comments

and don't forget to like the video thank you for watching

Loading...

Loading video analysis...