Using the RESTful API for Dynamic Websites

PHP and MySQL

When creating dynamic websites (can be personal, a web application, etc.) is it advisable to use API request calls instead of MySQL requests?

An example in my function getArticles()is whether I should use a native MySQL query, for example:

$sql = 'SELECT id, title, content
        FROM r_articles'
$result = mysql_query($sql) or die ('.. bla bla');

Or simply do a GET request: http://mysite.com/api/articles. Then (assuming the response is in JSON) format the response.

NOTE: The API, of course, must be created first.

+5
source share
3 answers

It completely depends on the type of your site. If you are building a small project with only a web interface, stay with your mysql calls.

, , . Android iPhone , api . API- . -, , .

+6

:

, . , ( / ..), , , - "Article", , , .

, , , GET PHP script . , , , , .

, , SQL, / ( SOAP JSON , :). , , , , - API- API- , , , .

+1

, . , API, , API , -, . , , , .

PS Depending on the expected size of your service / website, you may want to put this API on your subdomain (api.website.com).

+1
source

All Articles