3

If I have to create Web Services (REST/SOAP APIs) for Joomla based website. I have MySQL DataBase running with Joomla website and I wanted to create mobile apps for that.

By using same Database how I can create Rest/Soap web services? So if I write an article in Joomla site, it will display in mobile app as well.

I have few questions regarding this topic

  1. Should I use framework for this such as Slim Framework or other framework? (I know thats not a good idea because Joomla also runs a framework)
  2. How I can secure it?

  3. How to increase the performance?

Thanks in advance.

2
  • Are you really considering SOAP for WS? Commented Feb 3, 2016 at 21:21
  • @ValentinDespa thats why I asked :)
    – Joomler
    Commented Feb 4, 2016 at 5:18

4 Answers 4

3

Create a new php file (webapi.php) and save it to the root of your site.

Add in the required files to access the Joomla Framework like so:

//ALLOW DIRECT ACCESS
define('_JEXEC', 1);

require_once $_SERVER['DOCUMENT_ROOT'].'/includes/defines.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/includes/framework.php';

$app = JFactory::getApplication('site');
$app->initialise();

$JInput = JFactory::getApplication()->input;
$secretKey = $JInput->get('secretKey','','string');
$request_data = $JInput->get('request','','array');

Using the Joomla Framework allows you access to everything already in your database, no need for an external framework to do what Joomla is already built to do.

For encryption:

Have your mobile app pass a secret key and whatever other request data you may want to pass to query your database with.

Write some simple validation that will check your secret key against your site. Or for that matter use the secret key in your config file if you wanted to even though I don't recommend that. You can base64_encode they key on the mobile apps end then decode it back on your end. Or better still, HASH the key on the mobile apps end using a secret key, the check the value of the hash against your private key on the server side.

3
  • faced with 403 on joomla 1.5 , any solution?
    – Yuseferi
    Commented Jun 5, 2018 at 20:56
  • Not a clue, been a very long time since I have even looked at a 1.5 install.
    – Terry Carter
    Commented Aug 29, 2018 at 18:51
  • I've resolved that on commenting time, but I can't remember how right now :-)
    – Yuseferi
    Commented Aug 31, 2018 at 6:57
3

In Joomla 4 you can use the new webservices API where you have to create a plugin and some views to render the data. More information can be found in the official docs.

0

You can use com_ajax

Take a look at this: https://docs.joomla.org/Using_Joomla_Ajax_Interface

and also and example here: https://github.com/Joomla-Ajax-Interface/Ajax-Latest-Articles

0

Joomla 4 comes with a Web Services (REST) API for all of the core components.

You can find useful information:

  1. In that article
  2. In that video

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.