REST API

Simple Introduction of REST API

In the IT field REST API or API is the most important magical word.So, by this blog I'm going to touch that magical topic.

REST API (Representational State Transfer) is one of the easiest way of accessing web services.
It is a concept or architecture for managing information over the Internet.

REST API architecture

API(Application Programming Interface). It is a set or rules which allows one piece of software application to talk to another.
Following "rules" can include into he REST API
  1. Create
  2. Read
  3. Update and 
  4. Delete operations. 
Those are simply call it as CRUD operation. This REST API is called by HTTP server through 'url'.
    REST API is used by  making
    1. HTTP GET or
    2. HTTP POST or
    3. HTTP DELETE or
    4. HTTP PUT request from the client side to the server to get or to put some information to the server.
    It can give output in any format like CSV, JSON, RSS etc. So it is depend on requirement to which format you want to parse easily with your language.

     API s created by many languages such as NODEjs, JAVA, PHP and etc.

    From this blog I'm going to describe PHP REST API.

    REST API creation Steps
    Step1 : Use xammp server and phpMyadmin to create database,tables and its data.
    Step2 : Connect your database.
    Step3 : Write CRUD operation for your site.
    Step4 : Each and every CRUD operations are encoded by JSON (JavaScript Object Notation).

    How to call API

    Before  I go to Steps I'm going to briefly explain how will be displayed url when we query some data in browser.
    Ex:
    • https://www.google.com/search?client=ubuntu
    • https://www.facebook.com/Puradsifm/?hc_ref=ARQC2_B8Qmj
    You may see this kind of url on your browser when you query data

     So we going to use above way to call query by using php REST API.

    Step1 : Define url
    $url = "http://localhost/RESTAPI/api/product/read_one.php?id=".$id;
    Step2 : Initialize the url
    $client = curl_init($url);
    Step3 : Setting the option for url
    curl_setopt($client,CURLOPT_RETURNTRANSFER,true);
    Step4 : Execution the url
    $response = curl_exec($client);
    Step5 : decode the JSON code which is encode in the API
    $result = json_decode($response);
    Step6 : Release the url
    curl_close($ch);
    Step7 : Print the output
    print_r($result);

    This is the most simple way to call PHP API.

    On my next post I'll Explain how to create CRUD operation using PHP

    Comments

    Popular posts from this blog

    Easy understanding of MVC design architecture

    A / B Testing

    Firewall