Jump to content

  •  

  • iBotModz CBox


    Photo

    [Help] PHP/MySQL API [Help]


    • Please log in to reply
    3 replies to this topic

    #1 yoda302055

    yoda302055

      Apprentice Grade 2

    • Members+

    • 21 posts
    • Joined: 05-August 09
    • Gender:Male
    • Location:Texas

    Posted 05 May 2013 - 05:12 PM

    Hi guys i have been programming for a few years now... I still haven't been able to work with different languages. But now that i am actually driven. I would love it if someone could provide an example and explain how an API works. i have looked over the internet and stuff and i still don't understand how they work.

    Anyways, My goal for this to work with my Login application. Comparing what the user has entered to the Data Base.
     

     

    Any help would be appreciated. Thanks in advance everybody  :D



    #2 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 05 May 2013 - 05:57 PM

    You make an API like you make anything else.

     

    It interprets responses it gets and outputs data. The slight difference is there is no interface and the returned data is usually JSON/XML.

     

    EX:

     

    Hitting

    stats/members

     

    Would hit the database, then return the json file containing Members, xx etc.

     

    As you get more powerful, you begin to add basic things to output on each API request. EX, time of request, status of request, incoming API version, etc.

     

    Look at this API:

     

    https://stats.svc.ha...4/servicerecord

     

    You hit that, and get data. Raw data. You then interpret on your application (ex http://leafapp.co) and make something beautiful.



    #3 yoda302055

    yoda302055

      Apprentice Grade 2

    • Members+

    • 21 posts
    • Joined: 05-August 09
    • Gender:Male
    • Location:Texas

    Posted 05 May 2013 - 06:37 PM

    So the thing that I dont understand is how does it convert API?job=value to a function?


    Edited by yoda302055, 05 May 2013 - 06:37 PM.


    #4 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 05 May 2013 - 06:43 PM

    So the thing that I dont understand is how does it convert API?job=value to a function?

     

    You just parse it as it comes in, like regular user input. EX in php

    $what_to_do = $_POST['action'];
    
    switch ($what_to_do) {
    
      case "login":
          $this->login;
          break;
      case "foo":
          $this->foo;
          break;
    }
    
    print json_encode(array(''));