5

I need to create an API so an external client can perform actions on my custom extensions database table.

What would be the right approach?

  1. Should I use https://api.joomla.org/cms-3/ for this? How?! I did not find any examples.
  2. Put the API in a separate directory (for example /api/) and include the Joomla framework into my php?
  3. Or create a MVC extension, for example com_myapi?
  4. Should I use REST or any other method?
  5. Would com_api be a good start? (https://github.com/techjoomla/com_api) Did not find any documentation however…

The external client should be able to:

PUT - Modify an existing object on the server
POST - Create a new object on the server
DELETE - Remove an object on the server

I should then return a response (ok, or a specific error). JSON?

OR…. Am I overlooking some obvious other great solution?

Any suggestion is welcome!

3 Answers 3

9

There are a few options, but I use the jBackend extension.

Some positives of jBackend.

  • Nice clean JSON
  • Comes with good boilerplate code to get started
  • Manages API keys API endpoint code transmits and receives data
  • Basically exposes many common CMS functions as API endpoints
  • Has a normal looking Joomla admin UI for managing API keys
  • Documentation is good
  • Code is well structured and easy to read

We've been using it for a while so Joomla can be a Backend for mobile Apps. I did a talk about this at J&Beyond last week, which you can find at http://jandbeyond.org/programme.html?view=session&id=45&return=L3Byb2dyYW1tZS5odG1s

More details about jBackend are at http://www.selfget.com/products/jbackend.html . I think there is also a RedComponent extension that does a similar thing.

Whilst at J&Beyond, I attended Chris Davenport's talk on Joomla 3.6 and Beyond, which had some great details on Joomla's API features that may arrive in 3.6 - http://jandbeyond.org/programme.html?view=session&id=74&return=L3Byb2dyYW1tZS5odG1s

2
  • I just watched the video of jBackend, and it looks very promising. Thank you! Commented Jun 4, 2015 at 19:16
  • 2
    Ok, they/you got me convinced just bought the extension ;-) Commented Jun 4, 2015 at 19:30
3

If you need clean REST urls like : [GET] api/articles/1

You can have a look to my project : https://github.com/pvullioud/japi

or if you don't wont to use plugins, you have a more simple exemple here https://github.com/pvullioud/joomla-slimframework

3
  • 1
    Both GitHub links are dead. Commented May 23, 2018 at 17:07
  • I guess link changed to this one github.com/RemcoJanssen/japi
    – nik
    Commented Oct 15, 2018 at 6:45
  • Last commit in 2015. Dead.
    – Ralf
    Commented Mar 20, 2022 at 20:15
1

If a ready-made made extension is acceptable, then my suggestion is Headless Joomla and the Virtuemart plugin from codingmall. It gives you detailed info for any Joomla view using simple REST calls like this:

https://www.example.com/?cmjspkjson_opt=10

Output:

{
    "item": {
        "id": "1",
        "asset_id": "61",
        "title": "Getting Started",
        "alias": "getting-started",
        "introtext": "It's easy",
        "fulltext": "",
        "state": "1",
        "catid": "2",
        "created": "2019-08-29 14:35:43",
        "created_by": "581",
        ...
    },
    "pageclass_sfx": ""
}

A complex call example:

https://www.example.com/index.php?option=com_virtuemart&view=category&id=3&cmjspkjson_opt=10&reqobj[]=category.children

This will only return the required part instead of the full json output.

To save the number of requests, you may have more than one reqobj parameter.

Disclaimer: I provide technical assistance to CodingMall.com.

2
  • Welcome to Joomla Stack Exchange and thank you for contributing. Please take the tour to earn your first badge. If you have any affiliation with codingmall, it is required that you declare this. Commented Dec 15, 2019 at 10:11
  • 1
    Many thanks @mickmackusa Commented Dec 16, 2019 at 11:18

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.