What is a RESTful API?
What is a REST API? Does it tell something to stop or pause? Is a RESTful API a lazy program or one that initiates a rest state? If you’re at all interested in the web and how the various technologies behind it work, you will want to know about RESTful API.
An API is an Application Programming Interface. An API can be many things to many programmers but essentially it is a middleman that allows you to plug one program into another. Many programmers and developers will hide their core code to stop others from stealing all their hard work. If they want other programs to work with their program, they also have to make some code available to allow that interaction. That’s where APIs come in. A developer can create APIs that allow other programs to interface with their creation and provide extra features and interactions.
An API will be written with a certain structure formatted in a certain way that the resource can understand and that doesn’t use too many resources. Lots of websites, programs and platforms use APIs. Facebook has them, YouTube uses them, Google Maps has them, Android and iOS use them and most notable software will have some kind of programming interface. It is a good way of adding value and features without showing the world how your program is put together.
How are APIs used?
For example, say you wanted to build a set of camera filters for a phone. Rather than build your own camera app, you would use Apple’s or Android’s camera API to utilize the camera. The alternative would be to create entirely new camera software for each phone OS which is a lot of work. Instead, you just need to create an API that can communicate with the existing camera software and send your filter data to and from it.
APIs can also be used to access system resources, interface with other systems, provide value-add features to browsers and all that good stuff. If you just remember that an API is a piece of code that talks to other programs, you should be okay.
Another example would be Google Maps. If you want to add a Google Map to your website showing your location, you set up a Google Maps API with an HTTP GET query to pull the map from Google. This way, you get what you want without Google having to do anything or allow access to the internals of its mapping platform.
By using an API, Google Maps servers can satisfy millions of queries in a short period of time without overloading the maps server. The API queries will be correctly structured to be able to be satisfied using the fewest resources. The RESTful API ensures nothing can be written to the database and leaves no trace, leaving the map server to move on to the next query.
REST stands for REpresentational State Transfer. A RESTful API is used to transfer data from one resource to a client. As an example, a search engine uses a type of RESTful API. You enter a search term and the engine queries the servers. The serves transfer the correlating data to your browser for you to use. This is how RESTful API works.
You now know that an API allows external programs to interface with certain other programs. A RESTful API allows an independent program to communicate with a completely separate database, like in the search engine example above.
What makes a RESTful API work is that it is stateless and cacheable. Stateless means the query made by a RESTful API has no impact on the database. The query is not (always) logged, nothing is stored on the database and cannot write to the database. It is essentially read-only.
Being cacheable means the API client can store the information for future use so it doesn’t have to query the database every single time.
For the web, the API will likely use the HTTP method to process a request. The common HTTP methods are GET, POST, PUT and DELETE. In the search engine example, the RESTful API would use HTTP method to GET your search query data from the search engine database in order to display the search results.
Another example would be a Twitter user search. If you put the URL www.twitter.com/realDonaldTrump into a browser, the browser will use HTTP to GET Donald Trump’s data from Twitter and display it to you. As Twitter usernames are unique, the query will return the details to your browser.
The RESTful API is a rather elegant way of sharing information without impacting server performance or giving too much away. This tutorial just scratches the surface of how they work and integrate into the web but it should give you a basic idea of what’s going on.