I would love being able to use the exact same interface and way of defining route to create REST API !
I'm not sure what you mean, this is already possible using Laravel.
OctoberCMS is great for making a REST API. I've made an Android app for a friend with OctoberCMS as the backend and a REST API exposed via a plugin. You basically need to make a plugin for this and then expose the model and it's columns using JSON. The app would make the queries to the different routes to fetch and display data.
@Mohsin is it possible to have access to the code of the android app and the october plugin you've build ? Just to see how it's work and how to implement it ?
I really appreciate the help you've already given.
If you could clarify (this is my first time ever trying to create an API), what do you mean by, "expose the model"?
After creating the plugin and the component, I'm guessing code (like in your link) goes into the Plugin.php file? Does the default.htm stay empty (I imagine so)?
Anyway, thanks again!
Ugh... I guess that was a bad choice of words.
What I meant to say was that you translate the table into json and hand it to the application requesting the data. So, by exposing the model I mean to say that you present the data to your app so that it is able to get the data it needs from this backend. By default, these tables (or models) are well hidden and cannot be accessed from a browser normally. That is why I wrote a plugin with logic to add routes (or API nodes) from which it can access various tables.
If you see the code you’d notice I’ve done a
array('before' => 'auth.basic', function() each time. This is because the app that I made was done in a hurry so minimal security was added. Each time the app sends the username and password unencrypted and OctoberCMS responds are returns the model associated with the requested route in the JSON format ONLY IF the credentials are correct. So it is somewhat secure. A better way to do it is to use some security mechanism such as token exchange (I recommend JWT) so that each request is more secure. Ofcourse you can ignore this for now and do it my way until you get more familiar with how it works.
Awesome thanks. I like the way on how you seperate your API routes with controllers and not just messing up your routes.php file.
This is a useful extension.
While working on an iOS & Android app, I created my own stripped down version of an API by:
- creating a plugin with the command line
- adding a routes file within the plugin
- mapping a route to a controller method
This is just for the registration postback endpoint as the app requires no additional endpoints. It is built like a standard October website and is simply wrapped with an external service.
If anyone is interested turning your website into an app, I've written a guide on how to Build A Native App With October CMS that explains our workflow.
1-16 of 16