The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.
Font size: +
2 minutes reading time (436 words)

3 ways to do RESTful APIs in Joomla

3 ways to do RESTful APIs in Joomla

There has been a growing trend to start offering RESTful services for any web product, and Joomla is no exception. With Joomla, however, there is no "preferred" way of writing RESTful services so everyone (that includes us) is trying to build their own component and plugin to enable RESTful services in Joomla. We did the very first REST implementation with Joomla 1.5 which was made as a JSON based alternative to the then existing XML-RPC system that was already present. This blog attempts to list out the various approaches available and the benefits of using each. 

Using the JSON document type (format=json)

This is perhaps the oldest and most common way to do JSON over REST. This method is supported inherently by Joomla and developers just need to provide a view.json.php into each of their views to expose the data from the model via JSON. The framework on Framework (FOF) goes a step further and you don't need to create this file if the default output from the model is sufficient to you.

PROs

  1. No extra extensions needed
  2. Present directly inside a component so very easy to use model methods

CONs

  1. No good way of doing POST requests, so ideal only for fetching data

 

API component (com_api)

com_api is a component maintained by Techjoomla which follows a plugin based architecture. Developers write apps (plugins) that contain multiple resources. Eg: The user app may have a resource for fetching and saving user data and another resource for login. Similarly, the content app may have resources for articles & categories. This allows implementing all the GET, POST, PUT & DELETE methods.

PROs

  1. Very close to a true REST implementation
  2. Plugin structure allows flexibility in implementing REST resources
  3. Complex data models can be created since none of the resources is bound directly to any model
  4. Possible to introduce custom error handling

CONs

  1. Likely to introduce redundant code if model methods cannot be reused for fetching and saving of data

 

Expanding on the POC web services app

Understanding the need for web services, a very detailed API specification document has been created by Chris Davenport for the web services working group. The POC contains a few sample resources and a suggested/possible implementation of the web services. While this specification does not actually specify how the implementation should be done, it's more of a guideline for the URLs and data structures. A working example of the POC is here. 

PROs

  1. Once it's firmed up it'll be the default way to do APIs in Joomla
  2. Multilingual support

CONs

  1. In early stages of development

 

Is there a better way we've missed out? Have anything to add/improve on these? Let us know in the comments below!

 

20
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Update - Canva. Coming soon to a Joomla near you !
Avoid sending Emails while using JomSocial Notific...

Related Posts

 

Blog Topics