Any sample example for REST API example

9 views
Skip to first unread message

Kulveer Singh

unread,
Sep 7, 2019, 3:46:00 PM9/7/19
to Zotonic developers
Looking to make REST API app, is there any sample example for REST API example?

Marc Worrell

unread,
Sep 9, 2019, 4:52:44 AM9/9/19
to 'Marc Worrell' via Zotonic developers
Hi Kulveer,

The master (1.0-dev) has a new implementation for the API methods.

Previously you would make a service module.
This has been replaced with direct access to the models.

The API calls get mapped on m_get. m_post, and m_delete.

The url for a model is:


This calls your model in the same way as:

{{ m.yourmodel.some.path }}

In a template.

For a delete (calls m_yourmodel:m_delete/3):


And post (calls m_yourmodel:m_post/3):


The payload on a post can be anything that the model accepts.
It will be packed in a MQTT message that is delivered to the model.

The models will send their result back in the HTTP response (as JSON).
If you don’t expect an answer then you can tag an empty response topic to your
request:


Or, alternatively, you can route the response to some other topic:


We will document this in the master documentation which is being adapted to the new
capabilities.

Note that the 0.x uses the special service modules (as documented in the 0.x documentation).

We have changed this behavior so that the API methods (models) are accessed in the same way via:

 * HTTP
 * MQTT
 * templates

And also give access to the MQTT topics via a normal HTTP POST with payload.

Hope this explains a bit.

Cheers, Marc


On 7 Sep 2019, at 21:46, Kulveer Singh <kulvee...@gmail.com> wrote:

Looking to make REST API app, is there any sample example for REST API example?

--

---
You received this message because you are subscribed to the Google Groups "Zotonic developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotonic-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotonic-developers/c3ece6e8-f670-486e-b5da-c02ff26bfcde%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages