Welcome to an Introduction to Restful Services.
In this learning activity, we'll explore what RESTful services are,
how they interact with clients and servers, and finally,
understand how they work within an HTTP framework.
REST is an acronym for Representational State Transfer and it is an incredibly
important technology for all web applications.
It's used to build web services and applications that are lightweight,
maintainable, and scalable.
It allows a client to use the HTTP protocol to send and receive information from a remote server.
In fact, REST is only a conceptual model and not a technology unto itself.
Think of REST as a standardized way to transfer data or resources over HTTP.
So, what does the standardized approach look like?
When we look at the typical actions we take when dealing with data or resources in a system,
it comes down to four options: Create, Read, Update, and Delete, sometimes referred to as CRUD.
The REST model leverages HTTP verbs to implement each crud option.
By supplying an HTTP verb option with each CRUD operation, API's or
Application Program Interfaces, are created to work with resources and data.
The following verbs map to these CRUD operations:
HTTP GET is used to read a resource.
HTTP POST is used to create a resource.
HTTP PUT is used to update a resource.
And finally, HTTP DELETE is used to delete a resource.
Every system uses resources and every client wants access to those resources.
For the REST protocol, the client can be a web browser, a desktop application, or a mobile application.
Web browsers natively include the HTTP protocol to pass data back and forth.
The HTTP protocol is the underlying mechanism that allows clients to make
requests to remote servers.
Common requests include adding items to your online shopping cart,
logging in with a username and password, and paying for online merchandise.
Additionally, many desktop and mobile applications such as Skype and other
messenger services, use API's to enable the real-time conversations.
Each of these clients uses an already embedded HTTP protocol to transmit data
from the client to the server and receive responses.
REST and HTTP
REST is advantageous over other protocols
because it works with an operating software that supports the HTTP protocol.
It sits on top of the existing software and facilitates data transfers.
As an open protocol, HTTP doesn't require any proprietary language, ports, or other software.
REST was built using the HTTP framework because it's popular, simple, and used everywhere.
You make a request and you get results.
But it might be helpful to look at how HTTP supports something you do every day.
Say you're interested in finding marathons and races near you.
You go to Google, type in marathon races, and press enter.
You're using a GET statement to find resources related to these races on the web.
Your resources may include pictures, films, web pages, and articles about nearby races.
They may even include out-of-date pages, which will display the 404 error.
Your search on Google used the HTTP protocol to return the necessary
resources from the Internet's vast database.
A good, clean rest architecture is also stateless, which means the protocol
doesn't retain any information about what happened in the past.
For instance, the next time you open Google, it doesn't remember that you were
searching for marathon information, it opens up a new search page.
If the architecture was stateful, it would open to your previous search.
A RESTful service focuses on how to provide access to resources.
When you are developing it, you first need to identify your resources and then
determine how they're related to each other.
If your resource is comprised of data, instead of images or files, you need to
decide on the format you want to use to package that data.
Depending on your needs, you can decide to use JSON or XML
You also have the option of supplying either and leaving that decision up to
the consumer of your API.
In this case, we've used a GET method to find all of the races and it's been
returned as a collection of JSON objects.
We've typed in our query into the web server and it returned our results.
In this case, if we wanted to find all of the participants in the third race, we'd
pass in a three in our get statement.
It then returns all of the runners from the third race - The New York City 5K.
Whichever format you use, a good RESTful service needs to be understood by both
the client and the server.
REST is a great way of developing maintainable and scalable web services.
The REST model will continue to grow in popularity as technology continues to be
built upon API's.
Once you understand the basics, a RESTful service
can be easily implemented in Python, .NET, or Java.
Today, you've explored what RESTful services are,
how they interact with clients and servers,
and finally, how they work within an HTTP framework.
Congratulations, you have completed, An Introduction to Restful Services.