What is API
A REST API (also known as RESTful API) is an application programming interface that conforms to the constraints of REST architecture.
REST stands for representational state transfer. An API, or application program interface, makes it easy for developers to incorporate certain features into their own projects. A RESTful API has specific features that makes it different. When an API is described as RESTful, it conforms to the following six rules:
Client-server - The client and the server are separate. This means that, for example, there are no Java servlets that generate both data and its presentation in HTML; instead, HTML is generated on the server and sent to a client Web browser.
Stateless - There is no need to keep a context about the user's session on the server between requests since all session information is held by the client in cookies or other storage mechanisms available from JavaScript code running in the browser between requests.(no context kept between two requests)
Cacheable - Responses must define themselves as cacheable or not so a client can know if it can reuse local copies of data without checking with a server before making each request.(no context kept between two requests)
Layered system - The client cannot tell whether it is connected directly to the end server or through several layers of intermediaries such as proxies or caches.(hiding from clients which layers exist)
Code on demand - Servers are able to pass executable code or applets to clients when this allows better functionality.(Reuse similar components)
Uniform interface
What is REST(RESTful) API
REST is an architectural style for designing networked applications which is based on hypermedia and the stateless constraint.
It’s a collection of principles, constraints and properties that together define how components (mostly web services) should behave.
Among other things it defines how you can make calls to remote systems to perform operations like reading or updating information in them, without having to go through any additional steps first.
Typically this means that once you have a URL, you can use it directly - no logging in with a username/password first or adding authentication tokens as headers before making the call.
This makes REST APIs much easier to work with than more traditional APIs where you typically need some form of SDK to make use of them as they usually require some kind of OAuth handshake or similar before you can start making API calls.
Example of REST API
To get a better sense of how REST works, let's take a look at some of the most well-known examples of REST APIs.
Google Maps API is perhaps one of the best example for REST API. The Google Maps API allows you to navigate and explore geographical data on a 3D globe by using a web browser. You can also search and select places near a location (for example restaurants near me) or in any city/place (for example restaurants in Seattle).
The Twitter API is another well known RESTful API, which could be used to automate several tweets.
Conclusion
To conclude, REST API is an architectural paradigm that takes advantage of the existing HTTP protocols to make easily understandable APIs. The popularity of this design standard makes it easy to build and use. If you have yet to test out a RESTful web service, you can use Postman's "REST Client" extension for Google Chrome to test any web services built with the REST architecture.
Conclusion: With its ease of implementation, any developer can create useful APIs on his or her own that provide access to information in their databases.
You can build a RESTful API using PHP
To build a RESTful API using PHP, you should use an appropriate framework.PHP frameworks are used to speed up the development process of web applications by providing libraries for common tasks and a simple interface to access these libraries. Frameworks simplify some tasks that would be otherwise difficult or impossible to implement in less time. Some of the more popular are Symfony, CodeIgniter, CakePHP, Laravel and Zend Framework.
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.