What Is Meant By REST API And Its Methods Using PHP

admin_img Posted By Bajarangi soft , Posted On 16-09-2020

REST is an expand for Representational State Transfer. It is architectural style for distributed hypermedia systems and was first presented by Roy Fielding.

rest-api

 

-Api(Application program interface)
-Send and receive data between computers
-You want to display google maps on your site, but the maps are on google server, you need a way to ask Google to provide you with the maps.
- Building and Architeching REST API is not Easy task, especially when you have to do it for legacy PHP project.
- Google to send you requested maps is thorugh an API provided by google that  tells you which web address should you send request to get the data.
-REST(Representational State Transfer) is an API that defines a set of functions that programmers can use to send requests and receive response using the HTTp protocol methods such as GET and POST.
- Rest Api can be used by any site and appicantion no matter what  language is written in because request are based on HTTP
Protocol.

-REST is a logical choice for building APIs that allow users to connect to, manage and interact with cloud services flexibly in a distributed environment.
-An API for a website is code that allows two software programs to communicate with each other. 
-REST is not a Standerd. There will never be a standerds recommendation for Rest for Example. Rest Programming frameworks and 3rd party systems, working with REST is so simple that your organized can often create a custom solution with standerd liabrary features in languages like js,Javascript and C#/ASP.NET Web API.


Principles of REST API
 

 There are 6 ground principles laid down by Dr.fielding who was the one to difine the REST API design in 2000.
     1.Stateless
     2.Client-server
     3.Uniform interface
     4. Cacheable 
      5.Layered System   
     
6.Code on demand


1.Stateless

     - Each request  from client to server must contain all of the information server  to understand the request sent from the client.The server processes the request, a response is sent to the client through body, status or heders. Can be either a part of URl, query-string parameters,body, or even headers. URL used to uniquely identify resources & the body holds the state request resources.


2.Client-server

    -The probability across multiple platforms improve  the scalability of the server components.Servers are not concerned with the user interface or user state so thst server can be simpler and more scalable. Server and clients may also be replace and developed independently, as log the interface is not altered.


3. Uniform interface

- The Uniform interface throughout the application, REST the followed 4 interface constraints:
    1. Manipulation of resources through representations

     2. Self-descriptive messages
     3. Identification of resources
     4. Hypermidea as the engine of Application state

 

4. Cacheable

  - If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests. Better Performance, the Applications are often made cacheable. 

 

5.Layered system

- The Layered system architecture allows an application to be more stable by limiting component behavior.It  enables load balncing and provides shared caches for promoting  scalabilty. 


6.Code on demand

   - Optional constraint and is used least.Rest Allow client functionality to be extend by downloading and executing code in form of applets or script. Creating a smart application which does not rely on its own code structure.


Methods of REST API

       - A large number of people wrongly relate resource methods to HTTP GET/PUT/POST/DELETE methods. When I say CRUD operations, I mean that we create a resource, read a resource, update a resource and delete a resource.
                          
         C  ->  Create   ->  POST
        R  ->   Read   ->  GET
       U  ->  Update  ->  PUT
       D  ->  Delete   ->  DELETE
 
1.POST HTTP Method:
     - Create new article on your blog, we should send request to remote server
 2.GET Method:
       - View single article or list of articles
 3. PUT Method:
       - Edit and existing articles
 4.DELETE method:
      -Delete data from remote server

 

Related Post