Webservice responding with a JSON to an AJAX or API call

    • 75 posts
    March 16, 2018 6:28 PM EDT

    Hi all,

    I need to create some webservices that will be called by either ajax calls from within our site or API calls coming from another server, and will reply with a JSON.

    Is there an established best practice?

    Digging in the code i found two different ways to do that:

     

    if( $this->_getParam('sendNow', true) ) { return $this->_helper->json($data); else { $this->_helper->viewRenderer->setNoRender(true); $data = Zend_Json::encode($data); $this->getResponse()->setBody($data); }
       
     
    I assume the difference must be in how the dispatchment loop will proceed after the generation of the JSON but I'm not sure - do you know?

    This post was edited by socialenginestaff at March 17, 2018 6:41 AM EDT
    • Moderator
    • 6923 posts
    March 17, 2018 6:42 AM EDT

    Rather than delete your post, I edited and put the code in the required code tags as our forum rules say. Please remember to use the code tags. I don't have an answer to your question though.

    • 75 posts
    March 19, 2018 10:17 AM EDT

    odd - I did put the code tags...

    • Moderator
    • 6923 posts
    March 19, 2018 10:21 AM EDT

    Well that's weird. Are you sure you clicked the code icon and used the popup? That's the only way they work.

    • Moderator
    • 6923 posts
    March 19, 2018 10:22 AM EDT

    https://www.socialengine.com/marketplace/search?search=api there are a few API plugins. Would it be faster for you to use one of those or perhaps even use one of them as a guide to creating your own?

    • 75 posts
    March 19, 2018 10:40 AM EDT

    yeah I do need to create my own