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:

        https://example.com/api/model/yourmodel/get/some/path 
<https://example.com/api/model/yourmodel/get/some/path>

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):

        https://example.com/api/model/yourmodel/delete/some/path 
<https://example.com/api/model/yourmodel/delete/some/path>

And post (calls m_yourmodel:m_post/3):

        https://example.com/api/model/yourmodel/post/some/path 
<https://example.com/api/model/yourmodel/post/some/path>

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:

        https://example.com/api/model/yourmodel/post/some/path?response_topic= 
<https://example.com/api/model/yourmodel/post/some/path?response_topic=>

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

        https://example.com/api/model/yourmodel/post/some/path?response_topic= 
<https://example.com/api/model/yourmodel/post/some/path?response_topic=>some/topic/foo/bar

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 <kulveerjt1...@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-developers+unsubscr...@googlegroups.com 
> <mailto:zotonic-developers+unsubscr...@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
>  
> <https://groups.google.com/d/msgid/zotonic-developers/c3ece6e8-f670-486e-b5da-c02ff26bfcde%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 

--- 
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-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/zotonic-developers/3DC6CA81-8B5C-4289-8860-A90D0B35EBFA%40me.com.

Reply via email to