Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a RESTful API for Dynamic Websites

Tags:

rest

php

mysql

PHP and MySQL

In building dynamic websites (can be personal, web app, etc..), is it suitable to use API request calls, instead of MySQL queries?

Example in my function getArticles(), should I use a native MySQL query like:

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

Or, just execute a GET request to: http://mysite.com/api/articles. Then (supposed to be the response is in JSON) format the response.

NOTE: The API of course is to be created first.

like image 371
Ruel Avatar asked Jan 14 '11 08:01

Ruel


People also ask

Which platform is best for dynamic website?

PHP: PHP is an open-source development platform and a server-side scripting language offering versatility during development of dynamic websites.

What websites use restful API?

Many of the most popular web and cloud companies use REST APIs for their applications, including Facebook, YouTube, Twitter, and Google.

Does dynamic website use scripting?

Dynamic websites rely on both client-side and server-side scripting languages such as JavaScript, PHP or ASP.net. When a user accesses a dynamic website, the site can be changed through a code that is run in the browser and/or on the server.


1 Answers

That depends fully on the type of your site. If you're building a small project with just the webinterface, stay with your mysql calls.

If you're doing a site which shall grow big and serve more than one service, e.g. an android/iPhone application is already planned out, build the api and let both applications use it. APIs are great for scalability and serving to a lot of customers. However, for a web representation e.g. for your locals dentist its simply overhead.

like image 126
Samuel Herzog Avatar answered Oct 16 '22 01:10

Samuel Herzog