Zotonic 0.x to 1.0 migration - services

Skip to first unread message

Alvaro Pagliari

Jan 16, 2022, 7:51:44 AM1/16/22
to Zotonic users

On the journey to 1.0, I found a new big change. In the zotonic docs, there are references to the API services still working with some adjustments... process_get/2 was renamed to process_get/1. But I tried all sorts of things and it doesn't work, are the docs out of date?

I found a message in this group with the title "Big change coming - master in flux" from 2019 that states:
 * All ‘api services’ are removed and now unsupported, use models instead

So, I tried with call /api/model/my_model/get/my_method and it works!! But I have two questions:
* Is there a way to forbid a method in my m_get via this API?
* Is there a way to redirect my old /api/module/method call (to help with the migration)?


Álvaro Pagliari

Marc Worrell

Jan 16, 2022, 8:40:26 AM1/16/22
to zotoni...@googlegroups.com
Hei Alvaro!

Yes, we removed the API-services and unified the HTML, MQTT and template APIs in the models.

For access control you need to add access checks in the model m_get, m_post and m_delete (last two are optional). You will need these checks anyway, because you can call the APIs also from MQTT and the templates.

By examining the Context you can see if an API is called from a request context, especially by checking the controller handling the request.

In general I advise to be agnostic to the method used for calling the APIs and just check the capabilities of the current user. Maybe in the future we might add other protocols!

Is the process_get/1 mentioned in the release notes or somewhere else?

For handling the old paths, I have to check the options for the new API controller, knowing how we build these things there is probably thought of something :)

Cheers! Marc

Sent from my iPad

On 16 Jan 2022, at 13:51, Alvaro Pagliari <alva...@gmail.com> wrote:


You received this message because you are subscribed to the Google Groups "Zotonic users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotonic-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotonic-users/353778c5-2bd8-4694-a2cd-b5829bff93c9n%40googlegroups.com.

Alvaro Pagliari

Feb 1, 2022, 12:04:59 PM2/1/22
to Zotonic users
Hello Marc!

Sorry for the delay, I guess I missed the e-mail from your response...

So, I had seen the process_get/1 in the documentation, but it's gone now!!

I'll proceed to migrate everything to the model, including the ACL checks, it seems more organized this way.

Thanks for the clarification! 


Reply all
Reply to author
0 new messages